diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index d38507e9a72..dca446cb498 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -848,12 +848,11 @@ class PosOrder(models.Model): def _apply_invoice_payments(self): receivable_account = self.env["res.partner"]._find_accounting_partner(self.partner_id).with_company(self.company_id).property_account_receivable_id payment_moves = self.payment_ids.sudo().with_company(self.company_id)._create_payment_moves() - invoice_receivable = self.account_move.line_ids.filtered(lambda line: line.account_id == receivable_account) - # Reconcile the invoice to the created payment moves. - # But not when the invoice's total amount is zero because it's already reconciled. - if not invoice_receivable.reconciled and receivable_account.reconcile: - payment_receivables = payment_moves.mapped('line_ids').filtered(lambda line: line.account_id == receivable_account and line.partner_id) - (invoice_receivable | payment_receivables).sudo().with_company(self.company_id).reconcile() + if receivable_account.reconcile: + invoice_receivables = self.account_move.line_ids.filtered(lambda line: line.account_id == receivable_account and not line.reconciled) + if invoice_receivables: + payment_receivables = payment_moves.mapped('line_ids').filtered(lambda line: line.account_id == receivable_account and line.partner_id) + (invoice_receivables | payment_receivables).sudo().with_company(self.company_id).reconcile() return payment_moves @api.model