From dc1bb36d376cac6dd0942f46480a39a20b6303e9 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Mon, 8 Jun 2020 10:41:54 +0000 Subject: [PATCH] [FIX] sale: delete draft invoices with downpayments Create a SO, Validate it. Create Invoice: down payment (fixed amount) and validate invoice Now back to the SO. Create Invoice: Invoiceable lines (deduct down payments). A draft invoice is created. Try to delete it. User gets an error, this occur because the second invoice creation bind another invoice_line to the downpayment sale order line (first line was added when making the downpayment). When the user delete the invoice the sale order line should be deleted as well, but is still linked to an invoice so the error raise. Unlinking only unbinded sol fix the issue opw-2258218 closes odoo/odoo#53144 X-original-commit: 7c7275b8a943196975182a8e66cef0e82f87b21d Signed-off-by: Nicolas Martinelli (nim) --- addons/sale/models/account_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/models/account_invoice.py b/addons/sale/models/account_invoice.py index 8d363ed4132..5a9667330ea 100644 --- a/addons/sale/models/account_invoice.py +++ b/addons/sale/models/account_invoice.py @@ -36,7 +36,7 @@ class AccountMove(models.Model): self.fiscal_position_id = fiscal_position def unlink(self): - downpayment_lines = self.mapped('line_ids.sale_line_ids').filtered(lambda line: line.is_downpayment) + downpayment_lines = self.mapped('line_ids.sale_line_ids').filtered(lambda line: line.is_downpayment and line.invoice_lines <= self.mapped('line_ids')) res = super(AccountMove, self).unlink() if downpayment_lines: downpayment_lines.unlink()