[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) <vfe@odoo.com>
Signed-off-by: Kartik Chavda (kcv) <kcv@odoo.com>
This commit is contained in:
kcv-odoo
2024-03-20 13:52:25 +00:00
committed by Victor Feyens
parent eff58a91ca
commit 553fc002d7
2 changed files with 46 additions and 1 deletions
+3 -1
View File
@@ -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:
+43
View File
@@ -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({