[FIX] sale: fix order line amount update after downpayment invoice
Create a standard tax included in the product price. Add that tax to a product and the down payment product. Create a sales order (i.e. 1 line, 100$ total, 15% tax incl). Create a percentage down payment invoice, i.e. 50%. Post the downpayment invoice. Go back to the sale order The sale order line relative to the downpayment was asjusted to remove the tax amout while this should not occur when dealing with tax included in price Added test opw-2426294 closes odoo/odoo#65911 X-original-commit: 3b58b373e1c6c155f65b88c31cbb47794cb0a554 Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
@@ -16,9 +16,12 @@ class AccountMove(models.Model):
|
||||
for line in line_ids:
|
||||
try:
|
||||
line.sale_line_ids.tax_id = line.tax_ids
|
||||
#To keep positive amount on the sale order and to have the right price for the invoice
|
||||
#We need the - before our untaxed_amount_to_invoice
|
||||
line.sale_line_ids.price_unit = -line.sale_line_ids.untaxed_amount_to_invoice
|
||||
if all(line.tax_ids.mapped('price_include')):
|
||||
line.sale_line_ids.price_unit = line.price_unit
|
||||
else:
|
||||
#To keep positive amount on the sale order and to have the right price for the invoice
|
||||
#We need the - before our untaxed_amount_to_invoice
|
||||
line.sale_line_ids.price_unit = -line.sale_line_ids.untaxed_amount_to_invoice
|
||||
except UserError:
|
||||
# a UserError here means the SO was locked, which prevents changing the taxes
|
||||
# just ignore the error - this is a nice to have feature and should not be blocking
|
||||
|
||||
@@ -100,6 +100,36 @@ class TestSaleToInvoice(TestSaleCommon):
|
||||
self.assertEqual(len(invoice.invoice_line_ids.filtered(lambda l: not (l.display_type == 'line_section' and l.name == "Down Payments"))), len(self.sale_order.order_line), 'All lines should be invoiced')
|
||||
self.assertEqual(invoice.amount_total, self.sale_order.amount_total - downpayment_line.price_unit, 'Downpayment should be applied')
|
||||
|
||||
def test_downpayment_percentage_tax_icl(self):
|
||||
""" Test invoice with a percentage downpayment and an included tax
|
||||
Check the total amount of invoice is correct and equal to a respective sale order's total amount
|
||||
"""
|
||||
# Confirm the SO
|
||||
self.sale_order.action_confirm()
|
||||
tax_downpayment = self.company_data['default_tax_sale'].copy({'price_include': True})
|
||||
# Let's do an invoice for a deposit of 100
|
||||
product_id = self.env['ir.config_parameter'].sudo().get_param('sale.default_deposit_product_id')
|
||||
product_id = self.env['product.product'].browse(int(product_id)).exists()
|
||||
product_id.taxes_id = tax_downpayment.ids
|
||||
payment = self.env['sale.advance.payment.inv'].with_context(self.context).create({
|
||||
'advance_payment_method': 'percentage',
|
||||
'amount': 50,
|
||||
'deposit_account_id': self.company_data['default_account_revenue'].id,
|
||||
})
|
||||
payment.create_invoices()
|
||||
|
||||
self.assertEqual(len(self.sale_order.invoice_ids), 1, 'Invoice should be created for the SO')
|
||||
downpayment_line = self.sale_order.order_line.filtered(lambda l: l.is_downpayment)
|
||||
self.assertEqual(len(downpayment_line), 1, 'SO line downpayment should be created on SO')
|
||||
self.assertEqual(downpayment_line.price_unit, self.sale_order.amount_total/2, 'downpayment should have the correct amount')
|
||||
|
||||
invoice = self.sale_order.invoice_ids[0]
|
||||
downpayment_aml = invoice.line_ids.filtered(lambda l: not (l.display_type == 'line_section' and l.name == "Down Payments"))[0]
|
||||
self.assertEqual(downpayment_aml.price_total, self.sale_order.amount_total/2, 'downpayment should have the correct amount')
|
||||
self.assertEqual(downpayment_aml.price_unit, self.sale_order.amount_total/2, 'downpayment should have the correct amount')
|
||||
invoice.action_post()
|
||||
self.assertEqual(downpayment_line.price_unit, self.sale_order.amount_total/2, 'downpayment should have the correct amount')
|
||||
|
||||
def test_invoice_with_discount(self):
|
||||
""" Test invoice with a discount and check discount applied on both SO lines and an invoice lines """
|
||||
# Update discount and delivered quantity on SO lines
|
||||
|
||||
Reference in New Issue
Block a user