From 413e09e5fe0fcc45ebe6ec69ce3cacd21b7a2a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 13 Feb 2012 12:28:23 +0100 Subject: [PATCH 1/2] [FIX] Fixed wrong account_id not using property_account_receivable by default when using web-based POS front-end bzr revid: tde@openerp.com-20120213112823-6mdf83hqiawoca27 --- addons/point_of_sale/point_of_sale.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 0f188e584f0..19ce4b67026 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -55,9 +55,18 @@ class pos_order(osv.osv): #_logger.info("orders: %r", orders) list = [] for order in orders: - list.append(self.create(cr, uid, order, context)) + # set account_id using property_account_receivable if defined + property_obj = self.pool.get('ir.property') + account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context) + account_id = (account_def and account_def.id) or False + for statement_val in order['statement_ids']: + statement_val[2]['account_id'] = account_id or statement_val[2]['account_id'] + # create pos order + order_id = self.create(cr, uid, order, context) + list.append(order_id) + # mark as paid wf_service = netsvc.LocalService("workflow") - wf_service.trg_validate(uid, 'pos.order', list[-1], 'paid', cr) + wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr) return list def unlink(self, cr, uid, ids, context=None): From bd2e58fe4ffe59e0fb9e230a76e2bce9f6908b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 13 Feb 2012 17:12:01 +0100 Subject: [PATCH 2/2] [REF] Refactored the fix. It now uses the add_payment method to ensure that the back-end and front-end behaviors are the same. bzr revid: tde@openerp.com-20120213161201-xsc581kb4rdc65a5 --- addons/point_of_sale/point_of_sale.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 19ce4b67026..2445e4be10a 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -55,18 +55,22 @@ class pos_order(osv.osv): #_logger.info("orders: %r", orders) list = [] for order in orders: - # set account_id using property_account_receivable if defined - property_obj = self.pool.get('ir.property') - account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context) - account_id = (account_def and account_def.id) or False - for statement_val in order['statement_ids']: - statement_val[2]['account_id'] = account_id or statement_val[2]['account_id'] - # create pos order + # order :: {'name': 'Order 1329148448062', 'amount_paid': 9.42, 'lines': [[0, 0, {'discount': 0, 'price_unit': 1.46, 'product_id': 124, 'qty': 5}], [0, 0, {'discount': 0, 'price_unit': 0.53, 'product_id': 62, 'qty': 4}]], 'statement_ids': [[0, 0, {'journal_id': 7, 'amount': 9.42, 'name': '2012-02-13 15:54:12', 'account_id': 12, 'statement_id': 21}]], 'amount_tax': 0, 'amount_return': 0, 'amount_total': 9.42} + order_obj = self.pool.get('pos.order') + # get statements out of order because they will be generated with add_payment to ensure + # the module behavior is the same when using the front-end or the back-end + statement_ids = order.pop('statement_ids') order_id = self.create(cr, uid, order, context) list.append(order_id) - # mark as paid - wf_service = netsvc.LocalService("workflow") - wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr) + # call add_payment; refer to wizard/pos_payment for data structure + # add_payment launches the 'paid' signal to advance the workflow to the 'paid' state + data = { + 'journal': statement_ids[0][2]['journal_id'], + 'amount': order['amount_paid'], + 'payment_name': order['name'], + 'payment_date': statement_ids[0][2]['name'], + } + order_obj.add_payment(cr, uid, order_id, data, context=context) return list def unlink(self, cr, uid, ids, context=None):