Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||
ID | ||||||||
0041513 | ||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||
defect | [Retail Modules] Web POS | major | always | 2019-07-31 17:30 | 2019-08-02 08:11 | |||
Reporter | ucarrion | View Status | public | |||||
Assigned To | ranjith_qualiantech_com | |||||||
Priority | urgent | Resolution | fixed | Fixed in Version | RR19Q4 | |||
Status | closed | Fix in branch | Fixed in SCM revision | 52e7c0a063d7 | ||||
Projection | none | ETA | none | Target Version | ||||
OS | Any | Database | Any | Java version | ||||
OS Version | Database version | Ant version | ||||||
Product Version | SCM revision | |||||||
Merge Request Status | ||||||||
Review Assigned To | marvintm | |||||||
OBNetwork customer | Gold | |||||||
Support ticket | ||||||||
Regression level | ||||||||
Regression date | ||||||||
Regression introduced in release | ||||||||
Regression introduced by commit | ||||||||
Triggers an Emergency Pack | No | |||||||
Summary | 0041513: A receipt cannot be returned correctly in WebPOS when one of the addresses is not active | |||||||
Description | A receipt cannot be returned correctly in WebPOS when one of the addresses is not active. Some lines are not loaded at all, changing the total amount of the ticket loaded in webpos. | |||||||
Steps To Reproduce | Log in backend. Go to the Preference window and configure the following preferences: * 'Enable Remote for Product' with value Y * 'Enable Remote for Customer' with value Y Log in WebPOS Search for the customer Carl Studson Add a new address for the customer. Create a new ticket Assign the customer Carl Studson Assing one of the addresses for shipping and the other for invoicing. Add three different products to the ticket. Complete the receipt. Log in backend, go to the Business Partner window, find Carl Studson and deactivate the shipping address used in the ticket. Go back to WebPOS, select 'Verefied return' menu entry and try to return the ticket. | |||||||
Tags | No tags attached. | |||||||
Attached Files | ![]() # HG changeset patch # User Ranjith S R <ranjith@qualiantech.com> # Date 1564641611 -19800 # Thu Aug 01 12:10:11 2019 +0530 # Node ID b43089cbc69cf83c3dd878eac3dafbc0f6d2ae04 # Parent 80f5fc759c74ae8d8975fea84905ccfa1daa1403 Related to issue 41513 : Load Location from Backoffice if not present in local db * When loading receipt in verfied return, Location should be loaded from Backoffice if not present in local db diff -r 80f5fc759c74 -r b43089cbc69c web/org.openbravo.retail.returns/js/modalReturnLines.js --- a/web/org.openbravo.retail.returns/js/modalReturnLines.js Mon Jul 01 10:35:04 2019 +0000 +++ b/web/org.openbravo.retail.returns/js/modalReturnLines.js Thu Aug 01 12:10:11 2019 +0530 @@ -700,68 +700,22 @@ OB.UTIL.showLoading(false); return; } - var bpBillLoc, - me = this, - receipt = me.args.args.context.model.get('order'), - bpLoc = me.args.args.order.bpLocId, - noFoundCustomer = true, - isLoadedPartiallyFromBackend = false; + var me = this, + receipt = me.args.args.context.model.get('order'); if (OB.UTIL.isCrossStoreReceipt(me.args.args.order)) { receipt.set('organization', me.args.args.order.organization); receipt.set('documentType', me.args.args.order.documentTypeReturnId); receipt.set('priceList', me.args.args.order.priceList); receipt.set('priceIncludesTax', me.args.args.order.priceIncludesTax); } - var findBusinessPartner = function(bp) { - if ( - OB.MobileApp.model.hasPermission('OBPOS_remote.discount.bp', true) - ) { - var bpFilter = { - columns: ['businessPartner'], - operator: 'equals', - value: OB.MobileApp.model.get('businessPartner').id - }; - var remoteCriteria = [bpFilter]; - var criteriaFilter = {}; - criteriaFilter.remoteFilters = remoteCriteria; - OB.Dal.find( - OB.Model.DiscountFilterBusinessPartner, - criteriaFilter, - function(discountsBP) { - _.each(discountsBP.models, function(dsc) { - OB.Dal.saveOrUpdate( - dsc, - function() {}, - function() { - OB.error(arguments); - } - ); - }); - }, - function() { - OB.error(arguments); - } - ); - } - var locationForBpartner = function(bpLoc, billLoc) { - bp.set('shipLocName', bpLoc.get('name')); - bp.set('shipLocId', bpLoc.get('id')); - bp.set('shipPostalCode', bpLoc.get('postalCode')); - bp.set('shipCityName', bpLoc.get('cityName')); - bp.set('shipCountryName', bpLoc.get('countryName')); - bp.set('shipCountryId', bpLoc.get('countryId')); - bp.set('shipRegionId', bpLoc.get('regionId')); - bp.set('locName', bpLoc.get('name')); - bp.set('locId', bpLoc.get('id')); - bp.set('locationModel', bpLoc); - if (billLoc) { - bp.set('locName', billLoc.get('name')); - bp.set('locId', billLoc.get('id')); - bp.set('postalCode', billLoc.get('postalCode')); - bp.set('cityName', billLoc.get('cityName')); - bp.set('countryName', billLoc.get('countryName')); - bp.set('locationBillModel', billLoc); - } + me.args.args.context.model.get('orderList').loadCustomer( + { + bpId: me.args.args.order.bp, + bpLocId: me.args.args.order.bpLocId, + bpBillLocId: + me.args.args.order.bpBillLocId || me.args.args.order.bpLocId + }, + function(bp, bpLoc, billLoc) { me.nameLocation = bpLoc.get('name'); receipt.setBPandBPLoc(bp, false, true, function() { @@ -801,92 +755,6 @@ } ); }); - }; - if (isLoadedPartiallyFromBackend) { - locationForBpartner(bpLoc, bpBillLoc); - } else { - OB.Dal.get( - OB.Model.BPLocation, - me.args.args.order.bpLocId, - function(bpLoc) { - if (me.args.args.order.bpBillLocId) { - OB.Dal.get( - OB.Model.BPLocation, - me.args.args.order.bpBillLocId, - function(billLoc) { - locationForBpartner(bpLoc, billLoc); - }, - function() { - // TODO: Report errors properly - } - ); - } else { - locationForBpartner(bpLoc); - } - }, - function() { - // TODO: Report errors properly - }, - function() { - OB.UTIL.showConfirmation.display( - OB.I18N.getLabel('OBMOBC_Error'), - OB.I18N.getLabel('OBPOS_NoReceiptLoadedLocation') - ); - return; - } - ); - } - }; - //Check businesspartner - OB.Dal.get( - OB.Model.BusinessPartner, - this.args.args.order.bp, - function(bp) { - findBusinessPartner(bp); - }, - null, - function() { - var criteria = { - bpartnerId: me.args.args.order.bp, - bpLocationId: me.args.args.order.bpLocId - }; - if (me.args.args.order.bpLocId !== me.args.args.order.bpBillLocId) { - criteria.bpBillLocationId = me.args.args.order.bpBillLocId; - } - - new OB.DS.Request( - 'org.openbravo.retail.posterminal.master.LoadedCustomer' - ).exec( - criteria, - function(data) { - isLoadedPartiallyFromBackend = true; - bpLoc = OB.Dal.transform(OB.Model.BPLocation, data[1]); - //If we do not have a bill address we have an address for both - if (data.length === 3) { - bpBillLoc = OB.Dal.transform(OB.Model.BPLocation, data[2]); - } else { - bpBillLoc = OB.Dal.transform(OB.Model.BPLocation, data[1]); - } - findBusinessPartner( - OB.Dal.transform(OB.Model.BusinessPartner, data[0]) - ); - }, - function() { - if (noFoundCustomer) { - noFoundCustomer = false; - OB.UTIL.showConfirmation.display( - OB.I18N.getLabel('OBPOS_InformationTitle'), - OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), - [ - { - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - } - ] - ); - } - } - ); } ); }, ![]() # HG changeset patch # User Ranjith S R <ranjith@qualiantech.com> # Date 1564652771 -19800 # Thu Aug 01 15:16:11 2019 +0530 # Node ID 7f1abd68a97dea524a95cecf21cf336dc74a1052 # Parent b28693fe486d71e1bd2ea35af6e998be34b46c0b Related to issue 41513 : Added function to fetch Customer and Location when loading paid receipt diff -r b28693fe486d -r 7f1abd68a97d web/org.openbravo.retail.posterminal/js/model/order.js --- a/web/org.openbravo.retail.posterminal/js/model/order.js Tue Jul 30 18:11:43 2019 +0530 +++ b/web/org.openbravo.retail.posterminal/js/model/order.js Thu Aug 01 15:16:11 2019 +0530 @@ -5466,6 +5466,14 @@ }, function() { OB.error(arguments); + if (callback) { + callback(); + } + }, + function() { + if (callback) { + callback(); + } } ); } @@ -9524,6 +9532,186 @@ return OB.Collection.OrderList.newOrder(bp, propertiesToReset); }, + loadCustomer: function(model, callback) { + var bpId, + bpLocId, + bpBillLocId, + bpLoc, + bpBillLoc, + loadBusinesPartner, + loadLocations, + finalCallback, + isLoadedPartiallyFromBackend = false; + + bpId = model.bpId; + bpLocId = model.bpLocId; + bpBillLocId = model.bpBillLocId || model.bpLocId; + + finalCallback = function(bp, bpLoc, bpBillLoc) { + bp.set('locations', bp.get('locations') || []); + bp.set('shipLocId', bpLoc.get('id')); + bp.set('shipLocName', bpLoc.get('name')); + bp.set('shipPostalCode', bpLoc.get('postalCode')); + bp.set('shipCityName', bpLoc.get('cityName')); + bp.set('shipCountryId', bpLoc.get('countryId')); + bp.set('shipCountryName', bpLoc.get('countryName')); + bp.set('shipRegionId', bpLoc.get('regionId')); + bp.set('locId', bpLoc.get('id')); + bp.set('locName', bpLoc.get('name')); + bp.set('locationModel', bpLoc); + bp.get('locations').push(bpLoc); + if (bpBillLoc) { + bp.set('locId', bpBillLoc.get('id')); + bp.set('locName', bpBillLoc.get('name')); + bp.set('postalCode', bpBillLoc.get('postalCode')); + bp.set('cityName', bpBillLoc.get('cityName')); + bp.set('countryName', bpBillLoc.get('countryName')); + bp.set('locationBillModel', bpBillLoc); + bp.get('locations').push(bpBillLoc); + } + callback(bp, bpLoc, bpBillLoc); + }; + + loadBusinesPartner = function( + bpartnerId, + bpLocationId, + bpBillLocationId, + callback + ) { + var loadCustomerParameters = { + bpartnerId: bpartnerId, + bpLocationId: bpLocationId + }; + if (bpLocationId !== bpBillLocationId) { + loadCustomerParameters.bpBillLocationId = bpBillLocationId; + } + new OB.DS.Request( + 'org.openbravo.retail.posterminal.master.LoadedCustomer' + ).exec( + loadCustomerParameters, + function(data) { + isLoadedPartiallyFromBackend = true; + callback({ + bpartner: OB.Dal.transform(OB.Model.BusinessPartner, data[0]), + bpLoc: OB.Dal.transform(OB.Model.BPLocation, data[1]), + bpBillLoc: + bpLocationId !== bpBillLocationId + ? OB.Dal.transform(OB.Model.BPLocation, data[2]) + : null + }); + }, + function() { + OB.UTIL.showConfirmation.display( + OB.I18N.getLabel('OBPOS_InformationTitle'), + OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), + [ + { + label: OB.I18N.getLabel('OBPOS_LblOk'), + isConfirmButton: true + } + ] + ); + } + ); + }; + + loadLocations = function(bp) { + if (bpLocId === bpBillLocId) { + if (isLoadedPartiallyFromBackend) { + finalCallback(bp, bpLoc, null); + } else { + OB.Dal.get( + OB.Model.BPLocation, + bpLocId, + function(bpLoc) { + finalCallback(bp, bpLoc, null); + }, + function(tx, error) { + OB.UTIL.showError(error); + }, + function() { + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function( + data + ) { + finalCallback(bp, data.bpLoc, null); + }); + } + ); + } + } else { + if ( + isLoadedPartiallyFromBackend && + !OB.UTIL.isNullOrUndefined(bpLoc) && + !OB.UTIL.isNullOrUndefined(bpBillLoc) + ) { + finalCallback(bp, bpLoc, bpBillLoc); + } else { + var criteria = {}; + if ( + OB.MobileApp.model.hasPermission('OBPOS_remote.customer', true) + ) { + var remoteCriteria = [ + { + columns: ['id'], + operator: 'equals', + value: [bpLocId, bpBillLocId] + } + ]; + criteria.remoteFilters = remoteCriteria; + } else { + criteria._whereClause = + 'where c_bpartner_location_id in (?, ?)'; + criteria.params = [bpLocId, bpBillLocId]; + } + OB.Dal.find( + OB.Model.BPLocation, + criteria, + function(locations) { + if (locations.models.length === 2) { + _.each(locations.models, function(l) { + if (l.id === bpLocId) { + bpLoc = l; + } else if (l.id === bpBillLocId) { + bpBillLoc = l; + } + }); + finalCallback(bp, bpLoc, bpBillLoc); + } else { + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function( + data + ) { + finalCallback(bp, data.bpLoc, data.bpBillLoc); + }); + } + }, + function(tx, error) { + OB.UTIL.showError(error); + }, + bpLoc + ); + } + } + }; + OB.Dal.get( + OB.Model.BusinessPartner, + bpId, + function(bp) { + loadLocations(bp); + }, + null, + function() { + //Empty + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function(data) { + bpLoc = data.bpLoc; + if (bpLocId !== bpBillLocId) { + bpBillLoc = data.bpBillLoc; + } + loadLocations(data.bpartner); + }); + } + ); + }, + newPaidReceipt: function(model, callback) { var order = new Order(), lines, @@ -9531,16 +9719,9 @@ payments, curPayment, taxes, - bpId, - bpLocId, - bpLoc, - bpBillLocId, - bpBillLoc, numberOfLines = model.receiptLines.length, orderQty = 0, NoFoundProduct = true, - NoFoundCustomer = true, - isLoadedPartiallyFromBackend = false, execution = OB.UTIL.ProcessController.start('newPaidReceipt'); // Each payment that has been reverted stores the id of the reversal payment @@ -9643,571 +9824,404 @@ order.set('orderType', 1); } } - bpLocId = model.bpLocId; - bpBillLocId = model.bpBillLocId || model.bpLocId; - bpId = model.bp; - var bpartnerForProduct = function(bp) { - var loadProducts = function() { - var linepos = 0, - hasDeliveredProducts = false, - hasNotDeliveredProducts = false, - i, - sortedPayments = false; - _.each(model.receiptLines, function(iter) { - var price; - iter.linepos = linepos; - var addLineForProduct = function(prod) { - if ( - OB.MobileApp.model.hasPermission( - 'OBPOS_remote.product', - true - ) || - OB.UTIL.isCrossStoreReceipt(order) - ) { - var success = function() { - var productcriteria = { - columns: ['product'], - operator: 'equals', - value: prod.id, - isId: true - }; - var remoteCriteria = [productcriteria]; - var criteriaFilter = {}; - criteriaFilter.remoteFilters = remoteCriteria; - criteriaFilter.forceRemote = true; - criteriaFilter.remoteParams = {}; - criteriaFilter.remoteParams.crossStoreSearch = OB.UTIL.isCrossStoreReceipt( - order - ); - if (OB.UTIL.isCrossStoreReceipt(order)) { - criteriaFilter.remoteParams.productId = prod.get('id'); + var loadProducts = function() { + var linepos = 0, + hasDeliveredProducts = false, + hasNotDeliveredProducts = false, + i, + sortedPayments = false; + _.each(model.receiptLines, function(iter) { + var price; + iter.linepos = linepos; + var addLineForProduct = function(prod) { + if ( + OB.MobileApp.model.hasPermission( + 'OBPOS_remote.product', + true + ) || + OB.UTIL.isCrossStoreReceipt(order) + ) { + var success = function() { + var productcriteria = { + columns: ['product'], + operator: 'equals', + value: prod.id, + isId: true + }; + var remoteCriteria = [productcriteria]; + var criteriaFilter = {}; + criteriaFilter.remoteFilters = remoteCriteria; + criteriaFilter.forceRemote = true; + criteriaFilter.remoteParams = {}; + criteriaFilter.remoteParams.crossStoreSearch = OB.UTIL.isCrossStoreReceipt( + order + ); + if (OB.UTIL.isCrossStoreReceipt(order)) { + criteriaFilter.remoteParams.productId = prod.get('id'); + } + OB.Dal.find( + OB.Model.ProductCharacteristicValue, + criteriaFilter, + function(productcharacteristic) { + _.each(productcharacteristic.models, function(pchv) { + OB.Dal.saveOrUpdate( + pchv, + function() {}, + function() { + OB.error(arguments); + } + ); + }); + }, + function() { + OB.error(arguments); } - OB.Dal.find( - OB.Model.ProductCharacteristicValue, - criteriaFilter, - function(productcharacteristic) { - _.each(productcharacteristic.models, function(pchv) { - OB.Dal.saveOrUpdate( - pchv, - function() {}, - function() { - OB.error(arguments); - } - ); - }); + ); + }; + + if (!OB.UTIL.isCrossStoreReceipt(order)) { + OB.Dal.saveOrUpdate(prod, success, function() { + OB.error(arguments); + }); + } else { + success(); + } + } + // Set product services + order._loadRelatedServices( + prod.get('productType'), + prod.get('id'), + prod.get('productCategory'), + function(data) { + var hasservices; + if ( + !OB.UTIL.isNullOrUndefined(data) && + OB.DEC.number(iter.quantity) > 0 + ) { + hasservices = data.hasservices; + } + _.each(iter.promotions, function(promotion) { + OB.Dal.get( + OB.Model.Discount, + promotion.ruleId, + function(discount) { + if ( + discount && + OB.Model.Discounts.discountRules[ + discount.get('discountType') + ].addManual + ) { + var percentage; + if (discount.get('obdiscPercentage')) { + percentage = OB.DEC.mul( + OB.DEC.div(promotion.amt, iter.lineGrossAmount), + new BigDecimal('100') + ); + } + promotion.userAmt = percentage + ? percentage + : promotion.amt; + promotion.discountType = discount.get('discountType'); + promotion.manual = true; + } }, - function() { - OB.error(arguments); + function(tx, error) { + OB.UTIL.showError(error); } ); - }; - - if (!OB.UTIL.isCrossStoreReceipt(order)) { - OB.Dal.saveOrUpdate(prod, success, function() { - OB.error(arguments); - }); - } else { - success(); + }); + if ( + OB.MobileApp.model.hasPermission( + 'OBPOS_EnableSupportForProductAttributes', + true + ) + ) { + if ( + iter.attributeValue && + _.isString(iter.attributeValue) + ) { + var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson( + iter.attributeValue + ); + if ( + processedAttValues && + processedAttValues.keyValue && + _.isArray(processedAttValues.keyValue) && + processedAttValues.keyValue.length > 0 + ) { + iter.attSetInstanceDesc = + processedAttValues.description; + } + } + } + newline = new OrderLine({ + id: iter.lineId, + product: prod, + uOM: iter.uOM, + qty: OB.DEC.number(iter.quantity), + price: price, + priceList: + prod.get('listPrice') !== price + ? price + : prod.get('listPrice'), + promotions: iter.promotions, + description: iter.description, + priceIncludesTax: order.get('priceIncludesTax'), + hasRelatedServices: hasservices, + attributeValue: iter.attributeValue, + warehouse: { + id: iter.warehouse, + warehousename: iter.warehousename + }, + relatedLines: iter.relatedLines, + isEditable: true, + isDeletable: true, + attSetInstanceDesc: iter.attSetInstanceDesc + ? iter.attSetInstanceDesc + : null, + lineGrossAmount: iter.lineGrossAmount + }); + + // copy verbatim not owned properties -> modular properties. + _.each(iter, function(value, key) { + if (!newline.ownProperties[key]) { + newline.set(key, value); + } + }); + + // add the created line + lines.add(newline, { + at: iter.linepos + }); + numberOfLines--; + orderQty = OB.DEC.add(iter.quantity, orderQty); + if (numberOfLines === 0) { + lines.reset( + lines.sortBy(function(line) { + return line.get('linepos'); + }) + ); + order.set('lines', lines); + order.set('qty', orderQty); + order.set('json', JSON.stringify(order.toJSON())); + callback(order); + OB.UTIL.ProcessController.finish( + 'newPaidReceipt', + execution + ); } } - // Set product services - order._loadRelatedServices( - prod.get('productType'), - prod.get('id'), - prod.get('productCategory'), + ); + }; + + if (order.get('priceIncludesTax')) { + price = OB.DEC.number(iter.unitPrice); + } else { + price = OB.DEC.number( + iter.baseNetUnitPrice > 0 + ? iter.baseNetUnitPrice + : iter.unitPrice + ); + } + + if (!iter.deliveredQuantity) { + hasNotDeliveredProducts = true; + } else { + hasDeliveredProducts = true; + if (iter.deliveredQuantity < iter.quantity) { + hasNotDeliveredProducts = true; + } + } + + if (iter.relatedLines && !order.get('hasServices')) { + order.set('hasServices', true); + } + + OB.Dal.get( + OB.Model.Product, + iter.id, + function(product) { + addLineForProduct(product); + }, + null, + function() { + //Empty + new OB.DS.Request( + 'org.openbravo.retail.posterminal.master.LoadedProduct' + ).exec( + { + productId: iter.id, + salesOrderLineId: iter.lineId + }, function(data) { - var hasservices; - if ( - !OB.UTIL.isNullOrUndefined(data) && - OB.DEC.number(iter.quantity) > 0 - ) { - hasservices = data.hasservices; - } - _.each(iter.promotions, function(promotion) { - OB.Dal.get( - OB.Model.Discount, - promotion.ruleId, - function(discount) { - if ( - discount && - OB.Model.Discounts.discountRules[ - discount.get('discountType') - ].addManual - ) { - var percentage; - if (discount.get('obdiscPercentage')) { - percentage = OB.DEC.mul( - OB.DEC.div(promotion.amt, iter.lineGrossAmount), - new BigDecimal('100') - ); - } - promotion.userAmt = percentage - ? percentage - : promotion.amt; - promotion.discountType = discount.get( - 'discountType' - ); - promotion.manual = true; + addLineForProduct( + OB.Dal.transform(OB.Model.Product, data[0]) + ); + }, + function() { + if (NoFoundProduct) { + NoFoundProduct = false; + OB.UTIL.showConfirmation.display( + OB.I18N.getLabel('OBPOS_InformationTitle'), + OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), + [ + { + label: OB.I18N.getLabel('OBPOS_LblOk'), + isConfirmButton: true } - }, - function(tx, error) { - OB.UTIL.showError(error); - } - ); - }); - if ( - OB.MobileApp.model.hasPermission( - 'OBPOS_EnableSupportForProductAttributes', - true - ) - ) { - if ( - iter.attributeValue && - _.isString(iter.attributeValue) - ) { - var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson( - iter.attributeValue - ); - if ( - processedAttValues && - processedAttValues.keyValue && - _.isArray(processedAttValues.keyValue) && - processedAttValues.keyValue.length > 0 - ) { - iter.attSetInstanceDesc = - processedAttValues.description; - } - } - } - newline = new OrderLine({ - id: iter.lineId, - product: prod, - uOM: iter.uOM, - qty: OB.DEC.number(iter.quantity), - price: price, - priceList: - prod.get('listPrice') !== price - ? price - : prod.get('listPrice'), - promotions: iter.promotions, - description: iter.description, - priceIncludesTax: order.get('priceIncludesTax'), - hasRelatedServices: hasservices, - attributeValue: iter.attributeValue, - warehouse: { - id: iter.warehouse, - warehousename: iter.warehousename - }, - relatedLines: iter.relatedLines, - isEditable: true, - isDeletable: true, - attSetInstanceDesc: iter.attSetInstanceDesc - ? iter.attSetInstanceDesc - : null, - lineGrossAmount: iter.lineGrossAmount - }); - - // copy verbatim not owned properties -> modular properties. - _.each(iter, function(value, key) { - if (!newline.ownProperties[key]) { - newline.set(key, value); - } - }); - - // add the created line - lines.add(newline, { - at: iter.linepos - }); - numberOfLines--; - orderQty = OB.DEC.add(iter.quantity, orderQty); - if (numberOfLines === 0) { - lines.reset( - lines.sortBy(function(line) { - return line.get('linepos'); - }) - ); - order.set('lines', lines); - order.set('qty', orderQty); - order.set('json', JSON.stringify(order.toJSON())); - callback(order); - OB.UTIL.ProcessController.finish( - 'newPaidReceipt', - execution + ] ); } } ); - }; - - if (order.get('priceIncludesTax')) { - price = OB.DEC.number(iter.unitPrice); - } else { - price = OB.DEC.number( - iter.baseNetUnitPrice > 0 - ? iter.baseNetUnitPrice - : iter.unitPrice - ); - } - - if (!iter.deliveredQuantity) { - hasNotDeliveredProducts = true; - } else { - hasDeliveredProducts = true; - if (iter.deliveredQuantity < iter.quantity) { - hasNotDeliveredProducts = true; - } - } - - if (iter.relatedLines && !order.get('hasServices')) { - order.set('hasServices', true); - } - - OB.Dal.get( - OB.Model.Product, - iter.id, - function(product) { - addLineForProduct(product); - }, - null, - function() { - //Empty - new OB.DS.Request( - 'org.openbravo.retail.posterminal.master.LoadedProduct' - ).exec( - { - productId: iter.id, - salesOrderLineId: iter.lineId - }, - function(data) { - addLineForProduct( - OB.Dal.transform(OB.Model.Product, data[0]) - ); - }, - function() { - if (NoFoundProduct) { - NoFoundProduct = false; - OB.UTIL.showConfirmation.display( - OB.I18N.getLabel('OBPOS_InformationTitle'), - OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), - [ - { - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - } - ] - ); - } - } - ); - } + } + ); + linepos++; + }); + + function getReverserPayment(payment, Payments) { + return _.filter(model.receiptPayments, function(receiptPayment) { + return receiptPayment.paymentId === payment.reversedPaymentId; + })[0]; + } + i = 0; + // Sort payments array, puting reverser payments inmediatly after their reversed payment + while (i < model.receiptPayments.length) { + var payment = model.receiptPayments[i]; + if (payment.reversedPaymentId && !payment.isSorted) { + var reversed_index = model.receiptPayments.indexOf( + getReverserPayment(payment, model.receiptPayments) ); - linepos++; - }); - - function getReverserPayment(payment, Payments) { - return _.filter(model.receiptPayments, function(receiptPayment) { - return receiptPayment.paymentId === payment.reversedPaymentId; - })[0]; - } - i = 0; - // Sort payments array, puting reverser payments inmediatly after their reversed payment - while (i < model.receiptPayments.length) { - var payment = model.receiptPayments[i]; - if (payment.reversedPaymentId && !payment.isSorted) { - var reversed_index = model.receiptPayments.indexOf( - getReverserPayment(payment, model.receiptPayments) - ); - payment.isSorted = true; - if (i < reversed_index) { - model.receiptPayments.splice(i, 1); - model.receiptPayments.splice(reversed_index, 0, payment); - sortedPayments = true; - } else if (i > reversed_index + 1) { - model.receiptPayments.splice(i, 1); - model.receiptPayments.splice(reversed_index + 1, 0, payment); - sortedPayments = true; - } - } else { - i++; - } - } - if (sortedPayments) { - model.receiptPayments.forEach(function(receitPayment) { - if (receitPayment.isSorted) { - delete receitPayment.isSorted; - } - }); - } - //order.set('payments', model.receiptPayments); - payments = new PaymentLineList(); - _.each(model.receiptPayments, function(iter) { - var paymentProp; - curPayment = new PaymentLine(); - for (paymentProp in iter) { - if (iter.hasOwnProperty(paymentProp)) { - if (paymentProp === 'paymentDate') { - if ( - !OB.UTIL.isNullOrUndefined(iter[paymentProp]) && - moment(iter[paymentProp]).isValid() - ) { - curPayment.set( - paymentProp, - OB.I18N.normalizeDate(new Date(iter[paymentProp])) - ); - } else { - curPayment.set(paymentProp, null); - } - } else { - curPayment.set(paymentProp, iter[paymentProp]); - } - } - } - curPayment.set('orderGross', order.get('gross')); - curPayment.set('isPaid', order.get('isPaid')); - curPayment.set('date', new Date(iter.paymentDate)); - payments.add(curPayment); - }); - order.set('payments', payments); - order.adjustPayment(); - - order.set( - 'isPartiallyDelivered', - hasDeliveredProducts && hasNotDeliveredProducts ? true : false - ); - if (hasDeliveredProducts && !hasNotDeliveredProducts) { - order.set('isFullyDelivered', true); - } - if (order.get('isPartiallyDelivered')) { - var partiallyPaid = 0; - _.each( - _.filter(order.get('receiptLines'), function(reciptLine) { - return reciptLine.deliveredQuantity; - }), - function(deliveredLine) { - partiallyPaid = OB.DEC.add( - partiallyPaid, - OB.DEC.mul( - deliveredLine.deliveredQuantity, - deliveredLine.grossUnitPrice - ) - ); - } - ); - order.set('deliveredQuantityAmount', partiallyPaid); - if ( - order.get('deliveredQuantityAmount') && - order.get('deliveredQuantityAmount') > order.get('payment') - ) { - order.set('isDeliveredGreaterThanGross', true); - } - } - - taxes = {}; - _.each(model.receiptTaxes, function(iter) { - var taxProp; - taxes[iter.taxid] = {}; - for (taxProp in iter) { - if (iter.hasOwnProperty(taxProp)) { - taxes[iter.taxid][taxProp] = iter[taxProp]; - } + payment.isSorted = true; + if (i < reversed_index) { + model.receiptPayments.splice(i, 1); + model.receiptPayments.splice(reversed_index, 0, payment); + sortedPayments = true; + } else if (i > reversed_index + 1) { + model.receiptPayments.splice(i, 1); + model.receiptPayments.splice(reversed_index + 1, 0, payment); + sortedPayments = true; + } + } else { + i++; + } + } + if (sortedPayments) { + model.receiptPayments.forEach(function(receitPayment) { + if (receitPayment.isSorted) { + delete receitPayment.isSorted; } }); - order.set('taxes', taxes); - - if (!model.isLayaway && !model.isQuotation) { - if ( - model.totalamount > 0 && - order.get('payment') < model.totalamount - ) { - order.set('paidOnCredit', true); - } else if ( - model.totalamount < 0 && - (order.get('payment') === 0 || - OB.DEC.abs(model.totalamount) > order.get('payment')) - ) { - order.set('paidOnCredit', true); - } - } - if (model.receiptLines.length === 0) { - order.set('json', JSON.stringify(order.toJSON())); - callback(order); - OB.UTIL.ProcessController.finish('newPaidReceipt', execution); - } - }; - - var locationForBpartner = function(loc, billLoc) { - bp.set('shipLocName', loc.get('name')); - bp.set('shipLocId', loc.get('id')); - bp.set('shipPostalCode', loc.get('postalCode')); - bp.set('shipCityName', loc.get('cityName')); - bp.set('shipCountryName', loc.get('countryName')); - bp.set('shipCountryId', loc.get('countryId')); - bp.set('shipRegionId', loc.get('regionId')); - if (billLoc) { - bp.set('locName', billLoc.get('name')); - bp.set('locId', billLoc.get('id')); - bp.set('postalCode', billLoc.get('postalCode')); - bp.set('cityName', billLoc.get('cityName')); - bp.set('countryName', billLoc.get('countryName')); - bp.set('locationModel', billLoc); - } else { - bp.set('locationModel', loc); - } - + } + //order.set('payments', model.receiptPayments); + payments = new PaymentLineList(); + _.each(model.receiptPayments, function(iter) { + var paymentProp; + curPayment = new PaymentLine(); + for (paymentProp in iter) { + if (iter.hasOwnProperty(paymentProp)) { + if (paymentProp === 'paymentDate') { + if ( + !OB.UTIL.isNullOrUndefined(iter[paymentProp]) && + moment(iter[paymentProp]).isValid() + ) { + curPayment.set( + paymentProp, + OB.I18N.normalizeDate(new Date(iter[paymentProp])) + ); + } else { + curPayment.set(paymentProp, null); + } + } else { + curPayment.set(paymentProp, iter[paymentProp]); + } + } + } + curPayment.set('orderGross', order.get('gross')); + curPayment.set('isPaid', order.get('isPaid')); + curPayment.set('date', new Date(iter.paymentDate)); + payments.add(curPayment); + }); + order.set('payments', payments); + order.adjustPayment(); + + order.set( + 'isPartiallyDelivered', + hasDeliveredProducts && hasNotDeliveredProducts ? true : false + ); + if (hasDeliveredProducts && !hasNotDeliveredProducts) { + order.set('isFullyDelivered', true); + } + if (order.get('isPartiallyDelivered')) { + var partiallyPaid = 0; + _.each( + _.filter(order.get('receiptLines'), function(reciptLine) { + return reciptLine.deliveredQuantity; + }), + function(deliveredLine) { + partiallyPaid = OB.DEC.add( + partiallyPaid, + OB.DEC.mul( + deliveredLine.deliveredQuantity, + deliveredLine.grossUnitPrice + ) + ); + } + ); + order.set('deliveredQuantityAmount', partiallyPaid); + if ( + order.get('deliveredQuantityAmount') && + order.get('deliveredQuantityAmount') > order.get('payment') + ) { + order.set('isDeliveredGreaterThanGross', true); + } + } + + taxes = {}; + _.each(model.receiptTaxes, function(iter) { + var taxProp; + taxes[iter.taxid] = {}; + for (taxProp in iter) { + if (iter.hasOwnProperty(taxProp)) { + taxes[iter.taxid][taxProp] = iter[taxProp]; + } + } + }); + order.set('taxes', taxes); + + if (!model.isLayaway && !model.isQuotation) { + if ( + model.totalamount > 0 && + order.get('payment') < model.totalamount + ) { + order.set('paidOnCredit', true); + } else if ( + model.totalamount < 0 && + (order.get('payment') === 0 || + OB.DEC.abs(model.totalamount) > order.get('payment')) + ) { + order.set('paidOnCredit', true); + } + } + if (model.receiptLines.length === 0) { + order.set('json', JSON.stringify(order.toJSON())); + callback(order); + OB.UTIL.ProcessController.finish('newPaidReceipt', execution); + } + }; + + this.loadCustomer( + { + bpId: model.bp, + bpLocId: model.bpLocId, + bpBillLocId: model.bpBillLocId || model.bpLocId + }, + function(bp, loc, billLoc) { order.set('bp', bp); order.set('gross', model.totalamount); order.set('net', model.totalNetAmount); order.trigger('change:bp', order); loadProducts(); - }; - - bp.set('locations', bp.get('locations') || []); - if (bpLocId === bpBillLocId) { - if (isLoadedPartiallyFromBackend) { - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - } else { - OB.Dal.get( - OB.Model.BPLocation, - bpLocId, - function(bpLoc) { - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - }, - function(tx, error) { - OB.UTIL.showError(error); - }, - function() { - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function( - data - ) { - bpLoc = data.bpLoc; - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - }); - } - ); - } - } else { - if ( - isLoadedPartiallyFromBackend && - !OB.UTIL.isNullOrUndefined(bpLoc) && - !OB.UTIL.isNullOrUndefined(bpBillLoc) - ) { - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - } else { - var criteria = {}; - if ( - OB.MobileApp.model.hasPermission('OBPOS_remote.customer', true) - ) { - var remoteCriteria = [ - { - columns: ['id'], - operator: 'equals', - value: [bpLocId, bpBillLocId] - } - ]; - criteria.remoteFilters = remoteCriteria; - } else { - criteria._whereClause = - 'where c_bpartner_location_id in (?, ?)'; - criteria.params = [bpLocId, bpBillLocId]; - } - OB.Dal.find( - OB.Model.BPLocation, - criteria, - function(locations) { - if (locations.models.length === 2) { - _.each(locations.models, function(l) { - if (l.id === bpLocId) { - bpLoc = l; - } else if (l.id === bpBillLocId) { - bpBillLoc = l; - } - }); - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - } else { - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function( - data - ) { - bpLoc = data.bpLoc; - bpBillLoc = data.bpBillLoc; - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - }); - } - }, - function(tx, error) { - OB.UTIL.showError(error); - }, - bpLoc - ); - } - } - }; - var loadBusinesPartner = function( - bpartnerId, - bpLocationId, - bpBillLocationId, - callback - ) { - var loadCustomerParameters = { - bpartnerId: bpartnerId, - bpLocationId: bpLocationId - }; - if (bpLocationId !== bpBillLocationId) { - loadCustomerParameters.bpBillLocationId = bpBillLocationId; - } - new OB.DS.Request( - 'org.openbravo.retail.posterminal.master.LoadedCustomer' - ).exec( - loadCustomerParameters, - function(data) { - isLoadedPartiallyFromBackend = true; - callback({ - bpartner: OB.Dal.transform(OB.Model.BusinessPartner, data[0]), - bpLoc: OB.Dal.transform(OB.Model.BPLocation, data[1]), - bpBillLoc: - bpLocationId !== bpBillLocationId - ? OB.Dal.transform(OB.Model.BPLocation, data[2]) - : null - }); - }, - function() { - if (NoFoundCustomer) { - NoFoundCustomer = false; - OB.UTIL.showConfirmation.display( - OB.I18N.getLabel('OBPOS_InformationTitle'), - OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), - [ - { - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - } - ] - ); - } - } - ); - }; - OB.Dal.get( - OB.Model.BusinessPartner, - bpId, - function(bp) { - bpartnerForProduct(bp); - }, - null, - function() { - //Empty - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function(data) { - bpLoc = data.bpLoc; - if (bpLocId !== bpBillLocId) { - bpBillLoc = data.bpBillLoc; - } - bpartnerForProduct(data.bpartner); - }); } ); }, ![]() # HG changeset patch # User Ranjith S R <ranjith@qualiantech.com> # Date 1564654716 -19800 # Thu Aug 01 15:48:36 2019 +0530 # Node ID 6abb57ca27906364a460a3bbf75a4458955cc1a3 # Parent c449bf10654bac2d80068b2cb55b27b257d13dba Related to issue 41513 BUT 19Q1 : Load Location from Backoffice if not present in local db * When loading receipt in verfied return, Location should be loaded from Backoffice if not present in local db diff -r c449bf10654b -r 6abb57ca2790 web/org.openbravo.retail.returns/js/modalReturnLines.js --- a/web/org.openbravo.retail.returns/js/modalReturnLines.js Thu Aug 01 15:44:54 2019 +0530 +++ b/web/org.openbravo.retail.returns/js/modalReturnLines.js Thu Aug 01 15:48:36 2019 +0530 @@ -541,130 +541,37 @@ OB.UTIL.showLoading(false); return; } - var i, bpBillLoc, nameLocation = '', - me = this, - receipt = me.args.args.context.model.get('order'), - oldbp = receipt.get('bp'), - bpLoc = me.args.args.order.bpLocId, - noFoundCustomer = true, - isLoadedPartiallyFromBackend = false; + var me = this, + receipt = me.args.args.context.model.get('order'); - var findBusinessPartner = function (bp) { - if (OB.MobileApp.model.hasPermission('OBPOS_remote.discount.bp', true)) { - var bpFilter = { - columns: ['businessPartner'], - operator: 'equals', - value: OB.MobileApp.model.get('businessPartner').id - }; - var remoteCriteria = [bpFilter]; - var criteriaFilter = {}; - criteriaFilter.remoteFilters = remoteCriteria; - OB.Dal.find(OB.Model.DiscountFilterBusinessPartner, criteriaFilter, function (discountsBP) { - _.each(discountsBP.models, function (dsc) { - OB.Dal.saveOrUpdate(dsc, function () {}, function () { - OB.error(arguments); - }); - }); - }, function () { - OB.error(arguments); - }); - } - var locationForBpartner = function (bpLoc, billLoc) { - bp.set('shipLocName', bpLoc.get('name')); - bp.set('shipLocId', bpLoc.get('id')); - bp.set('shipPostalCode', bpLoc.get('postalCode')); - bp.set('shipCityName', bpLoc.get('cityName')); - bp.set('shipCountryName', bpLoc.get('countryName')); - bp.set('shipCountryId', bpLoc.get('countryId')); - bp.set('shipRegionId', bpLoc.get('regionId')); - bp.set('locName', bpLoc.get('name')); - bp.set('locId', bpLoc.get('id')); - bp.set('locationModel', bpLoc); - if (billLoc) { - bp.set('locName', billLoc.get('name')); - bp.set('locId', billLoc.get('id')); - bp.set('postalCode', billLoc.get('postalCode')); - bp.set('cityName', billLoc.get('cityName')); - bp.set('countryName', billLoc.get('countryName')); - bp.set('locationBillModel', billLoc); - } - me.nameLocation = bpLoc.get('name'); - - receipt.setBPandBPLoc(bp, false, true, function () { - - //If we do not let user to select qty to return of shipment lines, we do it automatically - if (!OB.MobileApp.model.hasPermission("OBPOS_SplitLinesInShipments", true)) { - me.args.args.order.receiptLines = me.autoSplitShipmentLines(me.args.args.order.receiptLines); - } - _.each(me.args.args.order.receiptLines, function (line) { - line.blockAddProduct = true; - line.isVerifiedReturn = true; - line.allowLayawayWithReturn = false; - }); + me.args.args.context.model.get('orderList').loadCustomer({ + bpId: me.args.args.order.bp, + bpLocId: me.args.args.order.bpLocId, + bpBillLocId: me.args.args.order.bpBillLocId || me.args.args.order.bpLocId + }, function (bp, bpLoc, billLoc) { + me.nameLocation = bpLoc.get('name'); - OB.UTIL.ReturnUtils.addReturnLines(receipt, me.args.args.order, me.args.args.order.receiptLines, function () { - receipt.calculateReceipt(function () { - receipt.save(function () { - OB.MobileApp.model.orderList.saveCurrent(); - OB.UTIL.showLoading(false); - }); - }); - me.args.args.cancelOperation = true; - OB.UTIL.HookManager.callbackExecutor(me.args.args, me.args.callbacks); - }); + receipt.setBPandBPLoc(bp, false, true, function () { + //If we do not let user to select qty to return of shipment lines, we do it automatically + if (!OB.MobileApp.model.hasPermission("OBPOS_SplitLinesInShipments", true)) { + me.args.args.order.receiptLines = me.autoSplitShipmentLines(me.args.args.order.receiptLines); + } + _.each(me.args.args.order.receiptLines, function (line) { + line.blockAddProduct = true; + line.isVerifiedReturn = true; + line.allowLayawayWithReturn = false; + }); + + OB.UTIL.ReturnUtils.addReturnLines(receipt, me.args.args.order, me.args.args.order.receiptLines, function () { + receipt.calculateReceipt(function () { + receipt.save(function () { + OB.MobileApp.model.orderList.saveCurrent(); + OB.UTIL.showLoading(false); }); - }; - if (isLoadedPartiallyFromBackend) { - locationForBpartner(bpLoc, bpBillLoc); - } else { - OB.Dal.get(OB.Model.BPLocation, me.args.args.order.bpLocId, function (bpLoc) { - if (me.args.args.order.bpBillLocId) { - OB.Dal.get(OB.Model.BPLocation, me.args.args.order.bpBillLocId, function (billLoc) { - locationForBpartner(bpLoc, billLoc); - }, function () { - // TODO: Report errors properly - }); - } else { - locationForBpartner(bpLoc); - } - - }, function () { - // TODO: Report errors properly - }, function () { - OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBMOBC_Error'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedLocation')); - return; }); - } - }; - //Check businesspartner - OB.Dal.get(OB.Model.BusinessPartner, this.args.args.order.bp, function (bp) { - findBusinessPartner(bp); - }, null, function () { - var criteria = { - bpartnerId: me.args.args.order.bp, - bpLocationId: me.args.args.order.bpLocId - }; - if (me.args.args.order.bpLocId !== me.args.args.order.bpBillLocId) { - criteria.bpBillLocationId = me.args.args.order.bpBillLocId; - } - new OB.DS.Request('org.openbravo.retail.posterminal.master.LoadedCustomer').exec(criteria, function (data) { - isLoadedPartiallyFromBackend = true; - bpLoc = OB.Dal.transform(OB.Model.BPLocation, data[1]); - //If we do not have a bill address we have an address for both - if (data.length === 3) { - bpBillLoc = OB.Dal.transform(OB.Model.BPLocation, data[2]); - } else { - bpBillLoc = OB.Dal.transform(OB.Model.BPLocation, data[1]); - } - findBusinessPartner(OB.Dal.transform(OB.Model.BusinessPartner, data[0])); - }, function () { - if (noFoundCustomer) { - noFoundCustomer = false; - OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_InformationTitle'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), [{ - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - }]); - } + me.args.args.cancelOperation = true; + OB.UTIL.HookManager.callbackExecutor(me.args.args, me.args.callbacks); + }); }); }); }, ![]() # HG changeset patch # User Ranjith S R <ranjith@qualiantech.com> # Date 1564655394 -19800 # Thu Aug 01 15:59:54 2019 +0530 # Node ID ac97a8664885ba86a4df6be3ecbee7a554bbe9cd # Parent 66f5bc302b7dfdc7bb20cd1843b8943d2aec81c2 Related to issue 41513 BUT 19Q1 : Added function to fetch Customer and Location when loading paid receipt diff -r 66f5bc302b7d -r ac97a8664885 web/org.openbravo.retail.posterminal/js/model/order.js --- a/web/org.openbravo.retail.posterminal/js/model/order.js Thu Aug 01 15:49:53 2019 +0530 +++ b/web/org.openbravo.retail.posterminal/js/model/order.js Thu Aug 01 15:59:54 2019 +0530 @@ -3812,6 +3812,13 @@ } }, function () { OB.error(arguments); + if (callback) { + callback(); + } + }, function () { + if (callback) { + callback(); + } }); } }; @@ -6592,14 +6599,143 @@ return OB.Collection.OrderList.newOrder(bp, propertiesToReset); }, + loadCustomer: function (model, callback) { + var bpId, bpLocId, bpBillLocId, bpLoc, bpBillLoc, loadBusinesPartner, loadLocations, finalCallback, isLoadedPartiallyFromBackend = false; + + bpId = model.bpId; + bpLocId = model.bpLocId; + bpBillLocId = model.bpBillLocId || model.bpLocId; + + finalCallback = function (bp, bpLoc, bpBillLoc) { + bp.set('locations', bp.get('locations') || []); + bp.set('shipLocId', bpLoc.get('id')); + bp.set('shipLocName', bpLoc.get('name')); + bp.set('shipPostalCode', bpLoc.get('postalCode')); + bp.set('shipCityName', bpLoc.get('cityName')); + bp.set('shipCountryId', bpLoc.get('countryId')); + bp.set('shipCountryName', bpLoc.get('countryName')); + bp.set('shipRegionId', bpLoc.get('regionId')); + bp.set('locId', bpLoc.get('id')); + bp.set('locName', bpLoc.get('name')); + bp.set('locationModel', bpLoc); + bp.get('locations').push(bpLoc); + if (bpBillLoc) { + bp.set('locId', bpBillLoc.get('id')); + bp.set('locName', bpBillLoc.get('name')); + bp.set('postalCode', bpBillLoc.get('postalCode')); + bp.set('cityName', bpBillLoc.get('cityName')); + bp.set('countryName', bpBillLoc.get('countryName')); + bp.set('locationBillModel', bpBillLoc); + bp.get('locations').push(bpBillLoc); + } + callback(bp, bpLoc, bpBillLoc); + }; + + loadBusinesPartner = function ( + bpartnerId, bpLocationId, bpBillLocationId, callback) { + var loadCustomerParameters = { + bpartnerId: bpartnerId, + bpLocationId: bpLocationId + }; + if (bpLocationId !== bpBillLocationId) { + loadCustomerParameters.bpBillLocationId = bpBillLocationId; + } + new OB.DS.Request('org.openbravo.retail.posterminal.master.LoadedCustomer').exec( + loadCustomerParameters, function (data) { + isLoadedPartiallyFromBackend = true; + callback({ + bpartner: OB.Dal.transform(OB.Model.BusinessPartner, data[0]), + bpLoc: OB.Dal.transform(OB.Model.BPLocation, data[1]), + bpBillLoc: bpLocationId !== bpBillLocationId ? OB.Dal.transform(OB.Model.BPLocation, data[2]) : null + }); + }, function () { + OB.UTIL.showConfirmation.display( + OB.I18N.getLabel('OBPOS_InformationTitle'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), [{ + label: OB.I18N.getLabel('OBPOS_LblOk'), + isConfirmButton: true + }]); + }); + }; + + loadLocations = function (bp) { + if (bpLocId === bpBillLocId) { + if (isLoadedPartiallyFromBackend) { + finalCallback(bp, bpLoc, null); + } else { + OB.Dal.get( + OB.Model.BPLocation, bpLocId, function (bpLoc) { + finalCallback(bp, bpLoc, null); + }, function (tx, error) { + OB.UTIL.showError(error); + }, function () { + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function ( + data) { + finalCallback(bp, data.bpLoc, null); + }); + }); + } + } else { + if ( + isLoadedPartiallyFromBackend && !OB.UTIL.isNullOrUndefined(bpLoc) && !OB.UTIL.isNullOrUndefined(bpBillLoc)) { + finalCallback(bp, bpLoc, bpBillLoc); + } else { + var criteria = {}; + if ( + OB.MobileApp.model.hasPermission('OBPOS_remote.customer', true)) { + var remoteCriteria = [{ + columns: ['id'], + operator: 'equals', + value: [bpLocId, bpBillLocId] + }]; + criteria.remoteFilters = remoteCriteria; + } else { + criteria._whereClause = 'where c_bpartner_location_id in (?, ?)'; + criteria.params = [bpLocId, bpBillLocId]; + } + OB.Dal.find( + OB.Model.BPLocation, criteria, function (locations) { + if (locations.models.length === 2) { + _.each(locations.models, function (l) { + if (l.id === bpLocId) { + bpLoc = l; + } else if (l.id === bpBillLocId) { + bpBillLoc = l; + } + }); + finalCallback(bp, bpLoc, bpBillLoc); + } else { + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function ( + data) { + finalCallback(bp, data.bpLoc, data.bpBillLoc); + }); + } + }, function (tx, error) { + OB.UTIL.showError(error); + }, bpLoc); + } + } + }; + OB.Dal.get( + OB.Model.BusinessPartner, bpId, function (bp) { + loadLocations(bp); + }, null, function () { + //Empty + loadBusinesPartner(bpId, bpLocId, bpBillLocId, function (data) { + bpLoc = data.bpLoc; + if (bpLocId !== bpBillLocId) { + bpBillLoc = data.bpBillLoc; + } + loadLocations(data.bpartner); + }); + }); + }, + newPaidReceipt: function (model, callback) { enyo.$.scrim.show(); var order = new Order(), - lines, newline, payments, curPayment, taxes, bpId, bpLocId, bpLoc, bpBillLocId, bpBillLoc, numberOfLines = model.receiptLines.length, + lines, newline, payments, curPayment, taxes, numberOfLines = model.receiptLines.length, orderQty = 0, - NoFoundProduct = true, - NoFoundCustomer = true, - isLoadedPartiallyFromBackend = false; + NoFoundProduct = true; // Each payment that has been reverted stores the id of the reversal payment // Web POS, instead of that, need to have the information of the payment reverted on the reversal payment @@ -6678,398 +6814,273 @@ order.set('orderType', 1); } } - bpLocId = model.bpLocId; - bpBillLocId = model.bpBillLocId || model.bpLocId; - bpId = model.bp; - var loadBusinesPartner, bpartnerForProduct = function (bp) { - var loadProducts = function () { - var linepos = 0, - hasDeliveredProducts = false, - hasNotDeliveredProducts = false, - i, sortedPayments = false; - _.each(model.receiptLines, function (iter) { - var price; - iter.linepos = linepos; - var addLineForProduct = function (prod) { - if (OB.MobileApp.model.hasPermission('OBPOS_remote.product', true)) { - OB.Dal.saveOrUpdate(prod, function () { - var productcriteria = { - columns: ['product'], - operator: 'equals', - value: prod.id, - isId: true - }; - var remoteCriteria = [productcriteria]; - var criteriaFilter = {}; - criteriaFilter.remoteFilters = remoteCriteria; - OB.Dal.find(OB.Model.ProductCharacteristicValue, criteriaFilter, function (productcharacteristic) { - _.each(productcharacteristic.models, function (pchv) { - OB.Dal.saveOrUpdate(pchv, function () {}, function () { - OB.error(arguments); - }); - }); - }, function () { + var loadProducts = function () { + var linepos = 0, + hasDeliveredProducts = false, + hasNotDeliveredProducts = false, + i, sortedPayments = false; + _.each(model.receiptLines, function (iter) { + var price; + iter.linepos = linepos; + var addLineForProduct = function (prod) { + if (OB.MobileApp.model.hasPermission('OBPOS_remote.product', true)) { + OB.Dal.saveOrUpdate(prod, function () { + var productcriteria = { + columns: ['product'], + operator: 'equals', + value: prod.id, + isId: true + }; + var remoteCriteria = [productcriteria]; + var criteriaFilter = {}; + criteriaFilter.remoteFilters = remoteCriteria; + OB.Dal.find(OB.Model.ProductCharacteristicValue, criteriaFilter, function (productcharacteristic) { + _.each(productcharacteristic.models, function (pchv) { + OB.Dal.saveOrUpdate(pchv, function () {}, function () { OB.error(arguments); }); - - }, function () { - OB.error(arguments); - }); - - } - // Set product services - order._loadRelatedServices(prod.get('productType'), prod.get('id'), prod.get('productCategory'), function (data) { - var hasservices; - if (!OB.UTIL.isNullOrUndefined(data) && OB.DEC.number(iter.quantity) > 0) { - hasservices = data.hasservices; - } - _.each(iter.promotions, function (promotion) { - OB.Dal.get(OB.Model.Discount, promotion.ruleId, function (discount) { - if (discount && OB.Model.Discounts.discountRules[discount.get('discountType')].addManual) { - var percentage; - if (discount.get('obdiscPercentage')) { - percentage = OB.DEC.mul(OB.DEC.div(promotion.amt, iter.lineGrossAmount), new BigDecimal('100')); - } - promotion.userAmt = percentage ? percentage : promotion.amt; - promotion.discountType = discount.get('discountType'); - promotion.manual = true; - } - }, function (tx, error) { - OB.UTIL.showError(error); - }); }); - if (OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true)) { - if (iter.attributeValue && _.isString(iter.attributeValue)) { - var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson(iter.attributeValue); - if (processedAttValues && processedAttValues.keyValue && _.isArray(processedAttValues.keyValue) && processedAttValues.keyValue.length > 0) { - iter.attSetInstanceDesc = processedAttValues.description; - } - } - } - newline = new OrderLine({ - id: iter.lineId, - product: prod, - uOM: iter.uOM, - qty: OB.DEC.number(iter.quantity), - price: price, - priceList: prod.get('listPrice') !== price ? price : prod.get('listPrice'), - promotions: iter.promotions, - description: iter.description, - priceIncludesTax: order.get('priceIncludesTax'), - hasRelatedServices: hasservices, - attributeValue: iter.attributeValue, - warehouse: { - id: iter.warehouse, - warehousename: iter.warehousename - }, - relatedLines: iter.relatedLines, - groupService: prod.get('groupProduct'), - isEditable: true, - isDeletable: true, - attSetInstanceDesc: (iter.attSetInstanceDesc ? iter.attSetInstanceDesc : null), - lineGrossAmount: iter.lineGrossAmount - }); - - // copy verbatim not owned properties -> modular properties. - _.each(iter, function (value, key) { - if (!newline.ownProperties[key]) { - newline.set(key, value); + }, function () { + OB.error(arguments); + }); + + }, function () { + OB.error(arguments); + }); + + } + // Set product services + order._loadRelatedServices(prod.get('productType'), prod.get('id'), prod.get('productCategory'), function (data) { + var hasservices; + if (!OB.UTIL.isNullOrUndefined(data) && OB.DEC.number(iter.quantity) > 0) { + hasservices = data.hasservices; + } + _.each(iter.promotions, function (promotion) { + OB.Dal.get(OB.Model.Discount, promotion.ruleId, function (discount) { + if (discount && OB.Model.Discounts.discountRules[discount.get('discountType')].addManual) { + var percentage; + if (discount.get('obdiscPercentage')) { + percentage = OB.DEC.mul(OB.DEC.div(promotion.amt, iter.lineGrossAmount), new BigDecimal('100')); } - }); - - // add the created line - lines.add(newline, { - at: iter.linepos - }); - numberOfLines--; - orderQty = OB.DEC.add(iter.quantity, orderQty); - if (numberOfLines === 0) { - lines.reset(lines.sortBy(function (line) { - return line.get('linepos'); - })); - order.set('lines', lines); - order.set('qty', orderQty); - order.set('json', JSON.stringify(order.toJSON())); - callback(order); - if (OB.MobileApp.view.openedPopup === null) { - enyo.$.scrim.hide(); - } + promotion.userAmt = percentage ? percentage : promotion.amt; + promotion.discountType = discount.get('discountType'); + promotion.manual = true; } + }, function (tx, error) { + OB.UTIL.showError(error); }); - }; - - if (order.get('priceIncludesTax')) { - price = OB.DEC.number(iter.unitPrice); - } else { - price = OB.DEC.number(iter.baseNetUnitPrice > 0 ? iter.baseNetUnitPrice : iter.unitPrice); - } - - if (!iter.deliveredQuantity) { - hasNotDeliveredProducts = true; - } else { - hasDeliveredProducts = true; - if (iter.deliveredQuantity < iter.quantity) { - hasNotDeliveredProducts = true; + }); + if (OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true)) { + if (iter.attributeValue && _.isString(iter.attributeValue)) { + var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson(iter.attributeValue); + if (processedAttValues && processedAttValues.keyValue && _.isArray(processedAttValues.keyValue) && processedAttValues.keyValue.length > 0) { + iter.attSetInstanceDesc = processedAttValues.description; + } + } } - } - - if (iter.relatedLines && !order.get('hasServices')) { - order.set('hasServices', true); - } - - OB.Dal.get(OB.Model.Product, iter.id, function (product) { - addLineForProduct(product); - }, null, function () { - //Empty - new OB.DS.Request('org.openbravo.retail.posterminal.master.LoadedProduct').exec({ - productId: iter.id, - salesOrderLineId: iter.lineId - }, function (data) { - addLineForProduct(OB.Dal.transform(OB.Model.Product, data[0])); - }, function () { - if (NoFoundProduct) { - NoFoundProduct = false; - OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_InformationTitle'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), [{ - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - }]); + newline = new OrderLine({ + id: iter.lineId, + product: prod, + uOM: iter.uOM, + qty: OB.DEC.number(iter.quantity), + price: price, + priceList: prod.get('listPrice') !== price ? price : prod.get('listPrice'), + promotions: iter.promotions, + description: iter.description, + priceIncludesTax: order.get('priceIncludesTax'), + hasRelatedServices: hasservices, + attributeValue: iter.attributeValue, + warehouse: { + id: iter.warehouse, + warehousename: iter.warehousename + }, + relatedLines: iter.relatedLines, + groupService: prod.get('groupProduct'), + isEditable: true, + isDeletable: true, + attSetInstanceDesc: (iter.attSetInstanceDesc ? iter.attSetInstanceDesc : null), + lineGrossAmount: iter.lineGrossAmount + }); + + // copy verbatim not owned properties -> modular properties. + _.each(iter, function (value, key) { + if (!newline.ownProperties[key]) { + newline.set(key, value); } }); - }); - linepos++; - }); - - function getReverserPayment(payment, Payments) { - return _.filter(model.receiptPayments, function (receiptPayment) { - return receiptPayment.paymentId === payment.reversedPaymentId; - })[0]; - } - i = 0; - // Sort payments array, puting reverser payments inmediatly after their reversed payment - while (i < model.receiptPayments.length) { - var payment = model.receiptPayments[i]; - if (payment.reversedPaymentId && !payment.isSorted) { - var reversed_index = model.receiptPayments.indexOf(getReverserPayment(payment, model.receiptPayments)); - payment.isSorted = true; - if (i < reversed_index) { - model.receiptPayments.splice(i, 1); - model.receiptPayments.splice(reversed_index, 0, payment); - sortedPayments = true; - } else if (i > reversed_index + 1) { - model.receiptPayments.splice(i, 1); - model.receiptPayments.splice(reversed_index + 1, 0, payment); - sortedPayments = true; - } - } else { - i++; - } - } - if (sortedPayments) { - model.receiptPayments.forEach(function (receitPayment) { - if (receitPayment.isSorted) { - delete receitPayment.isSorted; + + // add the created line + lines.add(newline, { + at: iter.linepos + }); + numberOfLines--; + orderQty = OB.DEC.add(iter.quantity, orderQty); + if (numberOfLines === 0) { + lines.reset(lines.sortBy(function (line) { + return line.get('linepos'); + })); + order.set('lines', lines); + order.set('qty', orderQty); + order.set('json', JSON.stringify(order.toJSON())); + callback(order); + if (OB.MobileApp.view.openedPopup === null) { + enyo.$.scrim.hide(); + } } }); + }; + + if (order.get('priceIncludesTax')) { + price = OB.DEC.number(iter.unitPrice); + } else { + price = OB.DEC.number(iter.baseNetUnitPrice > 0 ? iter.baseNetUnitPrice : iter.unitPrice); + } + + if (!iter.deliveredQuantity) { + hasNotDeliveredProducts = true; + } else { + hasDeliveredProducts = true; + if (iter.deliveredQuantity < iter.quantity) { + hasNotDeliveredProducts = true; } - //order.set('payments', model.receiptPayments); - payments = new PaymentLineList(); - _.each(model.receiptPayments, function (iter) { - var paymentProp; - curPayment = new PaymentLine(); - for (paymentProp in iter) { - if (iter.hasOwnProperty(paymentProp)) { - if (paymentProp === "paymentDate") { - if (!OB.UTIL.isNullOrUndefined(iter[paymentProp]) && moment(iter[paymentProp]).isValid()) { - curPayment.set(paymentProp, OB.I18N.normalizeDate(new Date(iter[paymentProp]))); - } else { - curPayment.set(paymentProp, null); - } - } else { - curPayment.set(paymentProp, iter[paymentProp]); - } - } - } - curPayment.set('orderGross', order.get('gross')); - curPayment.set('isPaid', order.get('isPaid')); - payments.add(curPayment); - }); - order.set('payments', payments); - order.adjustPayment(); - - order.set('isPartiallyDelivered', hasDeliveredProducts && hasNotDeliveredProducts ? true : false); - if (hasDeliveredProducts && !hasNotDeliveredProducts) { - order.set('isFullyDelivered', true); - } - if (order.get('isPartiallyDelivered')) { - var partiallyPaid = 0; - _.each(_.filter(order.get('receiptLines'), function (reciptLine) { - return reciptLine.deliveredQuantity; - }), function (deliveredLine) { - partiallyPaid = OB.DEC.add(partiallyPaid, OB.DEC.mul(deliveredLine.deliveredQuantity, deliveredLine.grossUnitPrice)); - }); - order.set('deliveredQuantityAmount', partiallyPaid); - if (order.get('deliveredQuantityAmount') && order.get('deliveredQuantityAmount') > order.get('payment')) { - order.set('isDeliveredGreaterThanGross', true); - } - } - - taxes = {}; - _.each(model.receiptTaxes, function (iter) { - var taxProp; - taxes[iter.taxid] = {}; - for (taxProp in iter) { - if (iter.hasOwnProperty(taxProp)) { - taxes[iter.taxid][taxProp] = iter[taxProp]; - } + } + + if (iter.relatedLines && !order.get('hasServices')) { + order.set('hasServices', true); + } + + OB.Dal.get(OB.Model.Product, iter.id, function (product) { + addLineForProduct(product); + }, null, function () { + //Empty + new OB.DS.Request('org.openbravo.retail.posterminal.master.LoadedProduct').exec({ + productId: iter.id, + salesOrderLineId: iter.lineId + }, function (data) { + addLineForProduct(OB.Dal.transform(OB.Model.Product, data[0])); + }, function () { + if (NoFoundProduct) { + NoFoundProduct = false; + OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_InformationTitle'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), [{ + label: OB.I18N.getLabel('OBPOS_LblOk'), + isConfirmButton: true + }]); } }); - order.set('taxes', taxes); - - if (!model.isLayaway && !model.isQuotation) { - if (model.totalamount > 0 && order.get('payment') < model.totalamount) { - order.set('paidOnCredit', true); - } else if (model.totalamount < 0 && (order.get('payment') === 0 || (OB.DEC.abs(model.totalamount)) > order.get('payment'))) { - order.set('paidOnCredit', true); + }); + linepos++; + }); + + function getReverserPayment(payment, Payments) { + return _.filter(model.receiptPayments, function (receiptPayment) { + return receiptPayment.paymentId === payment.reversedPaymentId; + })[0]; + } + i = 0; + // Sort payments array, puting reverser payments inmediatly after their reversed payment + while (i < model.receiptPayments.length) { + var payment = model.receiptPayments[i]; + if (payment.reversedPaymentId && !payment.isSorted) { + var reversed_index = model.receiptPayments.indexOf(getReverserPayment(payment, model.receiptPayments)); + payment.isSorted = true; + if (i < reversed_index) { + model.receiptPayments.splice(i, 1); + model.receiptPayments.splice(reversed_index, 0, payment); + sortedPayments = true; + } else if (i > reversed_index + 1) { + model.receiptPayments.splice(i, 1); + model.receiptPayments.splice(reversed_index + 1, 0, payment); + sortedPayments = true; + } + } else { + i++; + } + } + if (sortedPayments) { + model.receiptPayments.forEach(function (receitPayment) { + if (receitPayment.isSorted) { + delete receitPayment.isSorted; + } + }); + } + //order.set('payments', model.receiptPayments); + payments = new PaymentLineList(); + _.each(model.receiptPayments, function (iter) { + var paymentProp; + curPayment = new PaymentLine(); + for (paymentProp in iter) { + if (iter.hasOwnProperty(paymentProp)) { + if (paymentProp === "paymentDate") { + if (!OB.UTIL.isNullOrUndefined(iter[paymentProp]) && moment(iter[paymentProp]).isValid()) { + curPayment.set(paymentProp, OB.I18N.normalizeDate(new Date(iter[paymentProp]))); + } else { + curPayment.set(paymentProp, null); + } + } else { + curPayment.set(paymentProp, iter[paymentProp]); } } - if (model.receiptLines.length === 0) { - order.set('json', JSON.stringify(order.toJSON())); - callback(order); - enyo.$.scrim.hide(); - } - }; - - var locationForBpartner = function (loc, billLoc) { - bp.set('shipLocName', loc.get('name')); - bp.set('shipLocId', loc.get('id')); - bp.set('shipPostalCode', loc.get('postalCode')); - bp.set('shipCityName', loc.get('cityName')); - bp.set('shipCountryName', loc.get('countryName')); - bp.set('shipCountryId', loc.get('countryId')); - bp.set('shipRegionId', loc.get('regionId')); - if (billLoc) { - bp.set('locName', billLoc.get('name')); - bp.set('locId', billLoc.get('id')); - bp.set('postalCode', billLoc.get('postalCode')); - bp.set('cityName', billLoc.get('cityName')); - bp.set('countryName', billLoc.get('countryName')); - bp.set('locationModel', billLoc); - } else { - bp.set('locationModel', loc); - } - - order.set('bp', bp); - order.set('gross', model.totalamount); - order.set('net', model.totalNetAmount); - order.trigger('change:bp', order); - loadProducts(); - }; - - bp.set('locations', bp.get('locations') || []); - if (bpLocId === bpBillLocId) { - if (isLoadedPartiallyFromBackend) { - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - } else { - OB.Dal.get(OB.Model.BPLocation, bpLocId, function (bpLoc) { - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - }, function (tx, error) { - OB.UTIL.showError(error); - }, function () { - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function ( - data) { - bpLoc = data.bpLoc; - bp.get('locations').push(bpLoc); - locationForBpartner(bpLoc, bpLoc); - }); - }); + } + curPayment.set('orderGross', order.get('gross')); + curPayment.set('isPaid', order.get('isPaid')); + payments.add(curPayment); + }); + order.set('payments', payments); + order.adjustPayment(); + + order.set('isPartiallyDelivered', hasDeliveredProducts && hasNotDeliveredProducts ? true : false); + if (hasDeliveredProducts && !hasNotDeliveredProducts) { + order.set('isFullyDelivered', true); + } + if (order.get('isPartiallyDelivered')) { + var partiallyPaid = 0; + _.each(_.filter(order.get('receiptLines'), function (reciptLine) { + return reciptLine.deliveredQuantity; + }), function (deliveredLine) { + partiallyPaid = OB.DEC.add(partiallyPaid, OB.DEC.mul(deliveredLine.deliveredQuantity, deliveredLine.grossUnitPrice)); + }); + order.set('deliveredQuantityAmount', partiallyPaid); + if (order.get('deliveredQuantityAmount') && order.get('deliveredQuantityAmount') > order.get('payment')) { + order.set('isDeliveredGreaterThanGross', true); } - } else { - if (isLoadedPartiallyFromBackend && !OB.UTIL.isNullOrUndefined(bpLoc) && !OB.UTIL.isNullOrUndefined(bpBillLoc)) { - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - } else { - var criteria = {}; - if (OB.MobileApp.model.hasPermission('OBPOS_remote.customer', true)) { - var remoteCriteria = [{ - columns: ['id'], - operator: 'equals', - value: [bpLocId, bpBillLocId] - }]; - criteria.remoteFilters = remoteCriteria; - } else { - criteria._whereClause = "where c_bpartner_location_id in (?, ?)"; - criteria.params = [bpLocId, bpBillLocId]; + } + + taxes = {}; + _.each(model.receiptTaxes, function (iter) { + var taxProp; + taxes[iter.taxid] = {}; + for (taxProp in iter) { + if (iter.hasOwnProperty(taxProp)) { + taxes[iter.taxid][taxProp] = iter[taxProp]; } - OB.Dal.find(OB.Model.BPLocation, criteria, function (locations) { - if (locations.models.length === 2) { - _.each(locations.models, function (l) { - if (l.id === bpLocId) { - bpLoc = l; - } else if (l.id === bpBillLocId) { - bpBillLoc = l; - } - }); - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - } else { - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function ( - data) { - bpLoc = data.bpLoc; - bpBillLoc = data.bpBillLoc; - bp.get('locations').push(bpLoc, bpBillLoc); - locationForBpartner(bpLoc, bpBillLoc); - }); - } - }, function (tx, error) { - OB.UTIL.showError(error); - }, bpLoc); - } - - } - + }); + order.set('taxes', taxes); + + if (!model.isLayaway && !model.isQuotation) { + if (model.totalamount > 0 && order.get('payment') < model.totalamount) { + order.set('paidOnCredit', true); + } else if (model.totalamount < 0 && (order.get('payment') === 0 || (OB.DEC.abs(model.totalamount)) > order.get('payment'))) { + order.set('paidOnCredit', true); + } + } + if (model.receiptLines.length === 0) { + order.set('json', JSON.stringify(order.toJSON())); + callback(order); + enyo.$.scrim.hide(); + } }; - loadBusinesPartner = function ( - bpartnerId, bpLocationId, bpBillLocationId, callback) { - var loadCustomerParameters = { - bpartnerId: bpartnerId, - bpLocationId: bpLocationId - }; - if (bpLocationId !== bpBillLocationId) { - loadCustomerParameters.bpBillLocationId = bpBillLocationId; - } - new OB.DS.Request('org.openbravo.retail.posterminal.master.LoadedCustomer').exec( - loadCustomerParameters, function (data) { - isLoadedPartiallyFromBackend = true; - callback({ - bpartner: OB.Dal.transform(OB.Model.BusinessPartner, data[0]), - bpLoc: OB.Dal.transform(OB.Model.BPLocation, data[1]), - bpBillLoc: bpLocationId !== bpBillLocationId ? OB.Dal.transform(OB.Model.BPLocation, data[2]) : null - }); - }, function () { - if (NoFoundCustomer) { - NoFoundCustomer = false; - OB.UTIL.showConfirmation.display( - OB.I18N.getLabel('OBPOS_InformationTitle'), OB.I18N.getLabel('OBPOS_NoReceiptLoadedText'), [{ - label: OB.I18N.getLabel('OBPOS_LblOk'), - isConfirmButton: true - }]); - } - }); - }; - OB.Dal.get(OB.Model.BusinessPartner, bpId, function (bp) { - bpartnerForProduct(bp); - }, null, function () { - //Empty - loadBusinesPartner(bpId, bpLocId, bpBillLocId, function (data) { - bpLoc = data.bpLoc; - if (bpLocId !== bpBillLocId) { - bpBillLoc = data.bpBillLoc; - } - bpartnerForProduct(data.bpartner); - }); + + this.loadCustomer({ + bpId: model.bp, + bpLocId: model.bpLocId, + bpBillLocId: model.bpBillLocId || model.bpLocId + }, function (bp, loc, billLoc) { + order.set('bp', bp); + order.set('gross', model.totalamount); + order.set('net', model.totalNetAmount); + order.trigger('change:bp', order); + loadProducts(); }); }, newDynamicOrder: function (model, callback) { | |||||||
![]() |
||||||||
|
![]() |
|
(0113760) hgbot (developer) 2019-08-01 15:10 |
Repository: erp/pmods/org.openbravo.retail.returns Changeset: 27246c2eca99511d43fd2de65a68c331bd17ece8 Author: Ranjith S R <ranjith <at> qualiantech.com> Date: Thu Aug 01 18:37:59 2019 +0530 URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.returns/rev/27246c2eca99511d43fd2de65a68c331bd17ece8 [^] Related to issue 41513 : Load Location from Backoffice if not present in local db * When loading receipt in verfied return, Location should be loaded from Backoffice if not present in local database * Duplicate code removed and customer and location details fetched from loadCustomer fn --- M web/org.openbravo.retail.returns/js/modalReturnLines.js --- |
(0113761) hgbot (developer) 2019-08-01 15:11 |
Repository: erp/pmods/org.openbravo.retail.posterminal Changeset: 52e7c0a063d7278bfd2f8e9ef16982e2a95c5faf Author: Ranjith S R <ranjith <at> qualiantech.com> Date: Thu Aug 01 18:39:52 2019 +0530 URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/52e7c0a063d7278bfd2f8e9ef16982e2a95c5faf [^] Fixed issue 41513 : Added function to fetch Customer and Location when loading paid receipt * Added Common fn loadCustomer to fetch Customer and location from local database. If it is not present in local db, details will be fetched from backoffice thorugh LoadCustomer process --- M web/org.openbravo.retail.posterminal/js/model/order.js --- |
![]() |
|||
Date Modified | Username | Field | Change |
2019-07-31 17:30 | ucarrion | New Issue | |
2019-07-31 17:30 | ucarrion | Assigned To | => Retail |
2019-07-31 17:30 | ucarrion | OBNetwork customer | => Gold |
2019-07-31 17:30 | ucarrion | Resolution time | => 1564610400 |
2019-07-31 17:30 | ucarrion | Triggers an Emergency Pack | => No |
2019-07-31 17:31 | guillermogil | Assigned To | Retail => ranjith_qualiantech_com |
2019-07-31 17:31 | guillermogil | Status | new => scheduled |
2019-07-31 17:32 | guillermogil | Relationship added | related to 0041448 |
2019-07-31 17:40 | guillermogil | Steps to Reproduce Updated | View Revisions |
2019-08-01 08:42 | ranjith_qualiantech_com | File Added: issue 41513 source returns.patch | |
2019-08-01 08:42 | ranjith_qualiantech_com | File Added: issue 41513 source posterminal.patch | |
2019-08-01 11:47 | ranjith_qualiantech_com | File Added: issue 41513 source posterminal v2.patch | |
2019-08-01 11:50 | guillermogil | File Deleted: issue 41513 source posterminal.patch | |
2019-08-01 12:47 | ranjith_qualiantech_com | File Added: issue 41513 BUT 19Q1 source returns.patch | |
2019-08-01 12:47 | ranjith_qualiantech_com | File Added: issue 41513 BUT 19Q1 source posterminal.patch | |
2019-08-01 15:10 | hgbot | Checkin | |
2019-08-01 15:10 | hgbot | Note Added: 0113760 | |
2019-08-01 15:11 | hgbot | Checkin | |
2019-08-01 15:11 | hgbot | Note Added: 0113761 | |
2019-08-01 15:11 | hgbot | Status | scheduled => resolved |
2019-08-01 15:11 | hgbot | Resolution | open => fixed |
2019-08-01 15:11 | hgbot | Fixed in SCM revision | => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/52e7c0a063d7278bfd2f8e9ef16982e2a95c5faf [^] |
2019-08-02 08:11 | marvintm | Review Assigned To | => marvintm |
2019-08-02 08:11 | marvintm | Status | resolved => closed |
2019-08-02 08:11 | marvintm | Fixed in Version | => RR19Q4 |
Copyright © 2000 - 2009 MantisBT Group |