# HG changeset patch
# User Mario Castello <mario.castello@peoplewalking.com>
# Date 1475173335 21600
#      jue sep 29 12:22:15 2016 -0600
# Node ID 1e533963c2f50f1bae0018269b405dfc8fe39903
# Parent  3cc3b2de4ab106219c2bff670affc5aac78c184c
Fixed issue 33965: Added new function setBPLocationProperty to set the values of all locations properties from customer.
This function allow to set new properties in location model from customer model.

diff --git a/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js b/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js
--- a/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js
+++ b/web/org.openbravo.retail.posterminal/js/data/datacustomersave.js
@@ -29,6 +29,35 @@
           bpLocation, bpLocToSave = new OB.Model.BPLocation(),
           updateLocally;
 
+      var setBPLocationProperty = function (location, customer, isNew, sucesscallback) {
+          if (!OB.UTIL.isNullOrUndefined(location) && !OB.UTIL.isNullOrUndefined(customer)) {
+            if (isNew) {
+              location.set('id', customer.get('locId'));
+            }
+            _.each(OB.Model.BPLocation.getPropertiesForUpdate(), function (property) {
+              var key = property.name;
+              if (!OB.UTIL.isNullOrUndefined(key)) {
+                if (key === '_identifier') {
+                  location.set('_identifier', customer.get('locName'));
+                } else if (key === 'bpartner') {
+                  location.set(key, customer.get('id'));
+                } else if (key === 'name') {
+                  location.set(key, customer.get('locName'));
+                } else if (key === 'countryName') {
+                  location.set('countryName', OB.MobileApp.model.get('terminal').defaultbp_bpcountry_name);
+                } else if (key === 'countryId') {
+                  location.set('countryId', OB.MobileApp.model.get('terminal').defaultbp_bpcountry);
+                } else {
+                  location.set(key, customer.get(key));
+                }
+              }
+            });
+            if (sucesscallback) {
+              sucesscallback();
+            }
+          }
+          };
+
       bpToSave.set('isbeingprocessed', 'N');
       customer.set('createdBy', OB.MobileApp.model.get('orgUserId'));
       bpToSave.set('createdBy', OB.MobileApp.model.get('orgUserId'));
@@ -106,13 +135,14 @@
             //load the BPlocation and then update it
             OB.Dal.get(OB.Model.BPLocation, customer.get('locId'), function (bpLocToUpdate) {
               if (bpLocToUpdate) {
-                bpLocToUpdate.set('name', customer.get('locName'));
-                bpLocToUpdate.set('postalCode', customer.get('postalCode'));
-                bpLocToUpdate.set('cityName', customer.get('cityName'));
-                bpLocToUpdate.set('_identifier', customer.get('locName'));
-                OB.Dal.save(bpLocToUpdate, function () {}, function () {
-                  OB.error(arguments);
-                }, isNew);
+                // Set all properties to bplocation
+                setBPLocationProperty(bpLocToUpdate, customer, isNew, function () {
+                  OB.Dal.save(bpLocToUpdate, function () {
+                    //customer location created successfully. Nothing to do here.
+                  }, function () {
+                    OB.error(arguments);
+                  }, isNew);
+                });
               } else {
                 OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_errorSavingBPLoc_header'), OB.I18N.getLabel('OBPOS_errorSavingBPLoc_body'));
               }
@@ -120,20 +150,14 @@
               OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_errorSavingBPLoc_header'), OB.I18N.getLabel('OBPOS_errorSavingBPLoc_body'));
             });
           } else {
-            //create bploc from scratch
-            bpLocToSave.set('id', customer.get('locId'));
-            bpLocToSave.set('bpartner', customer.get('id'));
-            bpLocToSave.set('name', customer.get('locName'));
-            bpLocToSave.set('postalCode', customer.get('postalCode'));
-            bpLocToSave.set('cityName', customer.get('cityName'));
-            bpLocToSave.set('_identifier', customer.get('locName'));
-            bpLocToSave.set('countryName', OB.MobileApp.model.get('terminal').defaultbp_bpcountry_name);
-            bpLocToSave.set('countryId', OB.MobileApp.model.get('terminal').defaultbp_bpcountry);
-            OB.Dal.save(bpLocToSave, function () {
-              //customer location created successfully. Nothing to do here.
-            }, function () {
-              OB.error(arguments);
-            }, isNew);
+            //create bploc from scratch and set all properties
+            setBPLocationProperty(bpLocToSave, customer, isNew, function () {
+              OB.Dal.save(bpLocToSave, function () {
+                //customer location created successfully. Nothing to do here.
+              }, function () {
+                OB.error(arguments);
+              }, isNew);
+            });
           }
 
           if (isNew) {
