# HG changeset patch
# User Prakash M <prakash@qualiantech.com>
# Date 1457936346 -19800
# Node ID 04e1220c8d1eeac1cecec35183db8b32557a5cdb
# Parent  3ce53d443324729150226971be1afbbb07c5977e
Fixed Issue 769

diff --git a/web/org.openbravo.retail.posterminal/js/model/order.js b/web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js
@@ -1757,6 +1757,26 @@
     },
 
     /**
+     * Copy service line from existing order line to new order line 
+     */
+    createRelatedLines: function (lineEdited, newLine) {
+      var lines = this.get('lines'),
+          newRelatedLineObj = [];
+      lines.forEach(function (line) {
+        if (line.get('relatedLines')) {
+          line.get('relatedLines').forEach(function (rl) {
+            if (lineEdited.get("id") == rl.orderlineId) {
+              newRelatedLineObj[0] = {};
+              newRelatedLineObj[0].orderlineId = newLine.id;
+              newRelatedLineObj[0].productName = newLine.attributes.product.attributes._identifier;
+              line.set('relatedLines', OB.UTIL.mergeArrays(line.get('relatedLines'), newRelatedLineObj));
+            }
+          });
+        }
+      });
+    },
+
+    /**
      *  It looks for different lines for same product with exactly the same promotions
      *  to merge them in a single line
      */
@@ -3023,7 +3043,8 @@
               attrs: {
                 promotions: l.get('promotions'),
                 promotionCandidates: l.get('promotionCandidates'),
-                qtyToApplyDiscount: l.get('qtyToApplyDiscount')
+                qtyToApplyDiscount: l.get('qtyToApplyDiscount'),
+                hasRelatedServices: l.get('hasRelatedServices')
               }
             });
             lineToEdit.set('qty', OB.DEC.sub(lineToEdit.get('qty'), l.get('qty')), {
@@ -3202,7 +3223,8 @@
       });
       if (!linesCreated) {
         _.each(linesToCreate, function (line) {
-          me.createLine(line.product, line.qty, null, line.attrs);
+          newLine = me.createLine(line.product, line.qty, null, line.attrs);
+          me.createRelatedLines(lineToEdit, newLine);
         });
         linesCreated = true;
       }
@@ -4329,4 +4351,4 @@
   window.OB.Model.MultiOrders = MultiOrders;
 
   window.OB.Model.modelLoaders = [];
-}());
+}());
\ No newline at end of file
