From f43eadd28a4b4d8ee313a918cccdc9ad50ad3b33 Mon Sep 17 00:00:00 2001 From: Ayushi Gorai Date: Mon, 1 May 2023 13:34:50 +0000 Subject: [PATCH] [FIX] sale: prevent singleton error while creating invoices with sale credit When the user set some sale credit, while creation of invoice of multiple sale order which exceed the sale credit of a partner the user will get singleton error. steps to produce:- - Install 'sale' - Go to 'Setting' and enable the Sale Credit - Create two sale order with same customer and product which has ordered quantities - 'Conform' both the sale orders - Select both the sale orders - Go to actions and click 'Create Invoice' - Traceback is generated Applying this commit will fix this issue. sentry-4109773100 closes odoo/odoo#120600 X-original-commit: 565d1ad4c679d47e391cea7badf60d85ac2aa9ca Signed-off-by: John Laterre (jol) --- addons/sale/models/account_move.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/sale/models/account_move.py b/addons/sale/models/account_move.py index 0087647235a..11a46e3eb45 100644 --- a/addons/sale/models/account_move.py +++ b/addons/sale/models/account_move.py @@ -150,17 +150,19 @@ class AccountMove(models.Model): def _compute_partner_credit(self): super()._compute_partner_credit() for move in self: - sale_order = move.line_ids.sale_line_ids.order_id + sale_orders = move.line_ids.sale_line_ids.order_id amount_total_currency = move.currency_id._convert( move.tax_totals['amount_total'], move.company_currency_id, move.company_id, move.date ) - amount_to_invoice_currency = sale_order.currency_id._convert( - sale_order.amount_to_invoice, - move.company_currency_id, - move.company_id, - move.date + amount_to_invoice_currency = sum( + sale_order.currency_id._convert( + sale_order.amount_to_invoice, + move.company_currency_id, + move.company_id, + move.date + ) for sale_order in sale_orders ) move.partner_credit += max(amount_total_currency - amount_to_invoice_currency, 0.0)