Don't like ads? PRO users don't see any ads ;-)
Guest

OrderSave

By: a guest on Jul 3rd, 2012  |  syntax: JavaScript  |  size: 1.72 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   OB.DATA.OrderSave = function (context) {
  2.     this._id = 'logicOrderSave';
  3.     this.context = context;
  4.     this.receipt = context.modelorder;
  5.     this.receipt.on('closed', function () {
  6.       var me = this;
  7.       var docno = this.receipt.get('documentNo');
  8.       var json = this.receipt.serializeToJSON();
  9.       this.receipt.set('hasbeenpaid', 'Y');
  10.       this.receipt.set('isbeingprocessed', 'Y');
  11.       window.console.log('Antes del save: ' + me.receipt.get('id'));
  12.       OB.Dal.save(this.receipt, function(){
  13.         delete json.json;
  14.         window.console.log('Dentro del save: ' + me.receipt.get('id'));
  15.         me.proc.exec({
  16.           order: json
  17.         }, function (data, message) {
  18.           if (data && data.exception) {
  19.             OB.UTIL.showError(OB.I18N.getLabel('OBPOS_MsgReceiptNotSaved', [docno]));
  20.             //If there is an error while sending the order to the backend,
  21.             //we set the order as not being processed so that it can be sent again
  22.             me.receipt.set('isbeingprocessed', 'N');
  23.             OB.Dal.save(this.receipt, null, null);
  24.           } else {  
  25.             window.console.log('Dentro de la respuesta del save: ' + me.receipt.get('id'));
  26.             //In this case, the order was sent correctly, so we remove it from the buffer
  27.             OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_MsgReceiptSaved', [docno]));
  28.             OB.Dal.remove(me.receipt, null,null);
  29.           }
  30.         });
  31.       }, function(){
  32.           OB.UTIL.showError(OB.I18N.getLabel('OBPOS_MsgReceiptNotSaved', [docno]));
  33.       });
  34.       window.console.log('Fuera del save: ' + me.receipt.get('id'));
  35.     }, this);
  36.     this.proc = new OB.DS.Process('org.openbravo.retail.posterminal.ProcessOrder');
  37.   };