Skip to content
Snippets Groups Projects
Commit fe70f071 authored by Wolfgang Taferner's avatar Wolfgang Taferner Committed by Martin Trigaux
Browse files

[FIX] point_of_sale: backport of a2319b43 + fix

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

Add missing sudo to allow a user without accounting rights to close a session
and reconcile entries.

Closes #16517
parent 7e1a523f
Branches
Tags
No related merge requests found
......@@ -332,6 +332,20 @@ 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').mapped('line_ids') | order.account_move.line_ids | order.invoice_id.move_id.line_ids
aml = aml.filtered(lambda r: not r.reconciled and r.account_id.internal_type == 'receivable' and r.partner_id == order.partner_id.commercial_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.
_logger.error('Reconciliation did not work for order %s', order.name)
continue
def _default_session(self):
return self.env['pos.session'].search([('state', '=', 'opened'), ('user_id', '=', self.env.uid)], limit=1)
......
......@@ -27,6 +27,8 @@ class PosSession(models.Model):
if order.state not in ('paid'):
raise UserError(_("You cannot confirm all orders of this session, because they have not the 'paid' status"))
order.action_pos_order_done()
orders = session.order_ids.filtered(lambda order: order.state in ['invoiced', 'done'])
orders.sudo()._reconcile_payments()
config_id = fields.Many2one(
'pos.config', string='Point of Sale',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment