From 553fc002d7e0961f56ef494beead9ad3e702f7e3 Mon Sep 17 00:00:00 2001 From: kcv-odoo Date: Fri, 15 Mar 2024 11:13:14 +0530 Subject: [PATCH] [FIX] sale: re-compute downpayment related sol name Before this commit sol name was not reflacting invoice status when it moved to posted it only reflect draft and cancel state. This commit re-compute downpayment related sol name when invoice related to that sol get posted this way it'll update sol name to proper name instead of keeping always Draft string in it. opw-3768323 closes odoo/odoo#158094 X-original-commit: 40830f7e30ca8d84802088af17ade57f7b79998a Signed-off-by: Victor Feyens (vfe) Signed-off-by: Kartik Chavda (kcv) --- addons/sale/models/account_move.py | 4 ++- addons/sale/tests/test_sale_to_invoice.py | 43 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/account_move.py b/addons/sale/models/account_move.py index 48faa9306b1..1186f12041c 100644 --- a/addons/sale/models/account_move.py +++ b/addons/sale/models/account_move.py @@ -63,7 +63,9 @@ class AccountMove(models.Model): res = super(AccountMove, self).action_post() # We cannot change lines content on locked SO, changes on invoices are not forwarded to the SO if the SO is locked - downpayment_lines = self.line_ids.sale_line_ids.filtered(lambda l: l.is_downpayment and not l.display_type and not l.order_id.locked) + dp_lines = self.line_ids.sale_line_ids.filtered(lambda l: l.is_downpayment and not l.display_type) + dp_lines._compute_name() # Update the description of DP lines (Draft -> Posted) + downpayment_lines = dp_lines.filtered(lambda sol: not sol.order_id.locked) other_so_lines = downpayment_lines.order_id.order_line - downpayment_lines real_invoices = set(other_so_lines.invoice_lines.move_id) for so_dpl in downpayment_lines: diff --git a/addons/sale/tests/test_sale_to_invoice.py b/addons/sale/tests/test_sale_to_invoice.py index bc881ad2da1..9b3abe0d569 100644 --- a/addons/sale/tests/test_sale_to_invoice.py +++ b/addons/sale/tests/test_sale_to_invoice.py @@ -198,6 +198,49 @@ class TestSaleToInvoice(TestSaleCommon): sale_order.invoice_ids.action_post() self.assertEqual(downpayment_line[0].price_unit, 50, 'The down payment unit price should not change on SO') + def test_downpayment_line_name(self): + """ Test downpayment's SO line name is updated when invoice is posted. """ + # Create the SO with one line + sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({ + 'partner_id': self.partner_a.id, + 'partner_invoice_id': self.partner_a.id, + 'partner_shipping_id': self.partner_a.id, + 'pricelist_id': self.company_data['default_pricelist'].id, + 'order_line': [Command.create({ + 'product_id': self.company_data['product_order_no'].id, + 'product_uom_qty': 5, + 'tax_id': False, + }),] + }) + # Confirm the SO + sale_order.action_confirm() + # Update delivered quantity of SO line + sale_order.order_line.write({'qty_delivered': 5.0}) + context = { + 'default_journal_id': self.company_data['default_journal_sale'].id, + } + # Let's do an invoice for a down payment of 50 + self.env['sale.advance.payment.inv'].with_context(context).create({ + 'sale_order_ids': [Command.set(sale_order.ids)], + 'advance_payment_method': 'fixed', + 'fixed_amount': 50, + 'deposit_account_id': self.company_data['default_account_revenue'].id + }).create_invoices() + dp_line = sale_order.order_line.filtered( + lambda sol: sol.is_downpayment and not sol.display_type + ) + + dp_line.name = 'whatever' + + # Confirm the invoice + invoice = sale_order.invoice_ids + invoice.action_post() + + self.assertNotEqual( + dp_line.name, 'whatever', + "DP lines description should be recomputed when the linked invoice is posted", + ) + def test_downpayment_fixed_amount_with_zero_total_amount(self): # Create the SO with one line and amount total is zero sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({