# HG changeset patch
# User Rafa Alonso <rafael.alonso@openbravo.com>
# Date 1409172856 -7200
#      Wed Aug 27 22:54:16 2014 +0200
# Node ID 89b8d5f61735cb6ce7a21ce2b7a6a35eee0509f5
# Parent  c9de570612956e069066cd799bc7dbb69681d0af
Issue 27431: The business partner is required to pay a receipt

diff -r c9de57061295 -r 89b8d5f61735 web/org.openbravo.retail.posterminal/js/components/businesspartner.js
--- a/web/org.openbravo.retail.posterminal/js/components/businesspartner.js	Mon Jul 21 12:08:26 2014 +0000
+++ b/web/org.openbravo.retail.posterminal/js/components/businesspartner.js	Wed Aug 27 22:54:16 2014 +0200
@@ -39,19 +39,36 @@
     this.setContent(newCustomer);
   },
   orderChanged: function (oldValue) {
+    // Issue 27431: The business partner is required to pay a receipt
+    // Listen for changes in the business partner of the receipt
+    this.order.on('change:bp', function (model) {
+      // If the receipt is editable another logic is handling the state of the pay button
+      if (!model.get('isEditable')) {
+        return;
+      }
+      var bp = model.get('bp');
+      // If there is no business partner, keep the state of the pay button. Check I
+      if (!bp) {
+        return;
+      }
+      // If there is no business partner, keep the state of the pay button. Check II
+      if (bp.get('_identifier').length === 0) {
+        return;
+      }
+      // If the above conditions are passed, enable the pay button
+      this.renderCustomer(bp.get('_identifier'));
+      OB.MobileApp.view.waterfall('onAppliedDiscount');
+    }, this);
+
     if (this.order.get('bp')) {
       this.renderCustomer(this.order.get('bp').get('_identifier'));
+      // A business partner is present. Enable the pay button.
+      OB.MobileApp.view.waterfall('onAppliedDiscount');
     } else {
+      // A business partner is not present. Disable the pay button.
+      OB.MobileApp.view.waterfall('onApplyingDiscount');
       this.renderCustomer('');
     }
-
-    this.order.on('change:bp', function (model) {
-      if (model.get('bp')) {
-        this.renderCustomer(model.get('bp').get('_identifier'));
-      } else {
-        this.renderCustomer('');
-      }
-    }, this);
   }
 });
 
