From a2319b431b3d4f12a932ac8cda1ce62ecd6b6d2f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 10 Jan 2017 11:16:41 +0100 Subject: [PATCH] [IMP] point_of_sale: reconcile payment When a PoS order is closed, the payment and the sales journal item are not automatically reconciled. This potentially leaves a lot of unreconciled entries for a customer, which will appear in his follow-up report. This introduces an auto-reconciliation process upon order closing. The process restricts the reconciliation to an order individually, i.e. we don't try to cross-reconcile several orders for a customer. opw-697565 --- addons/point_of_sale/models/pos_order.py | 13 +++++++++++++ addons/point_of_sale/models/pos_session.py | 2 ++ 2 files changed, 15 insertions(+) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index a0c1170ee38..b041fa34565 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -316,6 +316,19 @@ class PosOrder(models.Model): move.sudo().post() return True + def _reconcile_payments(self): + for order in self: + aml = order.statement_ids.mapped('journal_entry_ids') | order.account_move.line_ids + aml = aml.filtered(lambda r: not r.reconciled and r.account_id.internal_type == 'receivable' and r.partner_id == order.partner_id) + try: + aml.reconcile() + except: + # There might be unexpected situations where the automatic reconciliation won't + # work. We don't want the user to be blocked because of this, since the automatic + # reconciliation is introduced for convenience, not for mandatory accounting + # reasons. + continue + def _default_session(self): return self.env['pos.session'].search([('state', '=', 'opened'), ('user_id', '=', self.env.uid)], limit=1) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 8dee7d3efeb..6276d932caf 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -28,6 +28,8 @@ class PosSession(models.Model): if order.state not in ('paid', 'invoiced'): raise UserError(_("You cannot confirm all orders of this session, because they don't have the 'paid' status")) order.action_pos_order_done() + orders = session.order_ids.filtered(lambda order: order.state == 'done') + orders._reconcile_payments() config_id = fields.Many2one( 'pos.config', string='Point of Sale',