[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) <jol@odoo.com>
This commit is contained in:
Ayushi Gorai
2023-05-08 17:10:45 +02:00
parent 17882e3262
commit f43eadd28a
+8 -6
View File
@@ -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)