[FIX] purchase: prevent unnecesary change of currency
Steps to reproduce: - put the currency of the bill to eur - change the partner with a partner with no purchase currency set Issue: The bill is re-set to usd Note: addendum to https://github.com/odoo/odoo/pull/116852 opw-3233527 closes odoo/odoo#119753 X-original-commit: 51ff9c6026b8f9079aba7c9e26891f62c782761d Signed-off-by: Cedric Snauwaert <csn@odoo.com> Signed-off-by: Yolann Sabaux (yosa) <yosa@odoo.com>
This commit is contained in:
@@ -87,7 +87,7 @@ class AccountMove(models.Model):
|
||||
currency_id = (
|
||||
self.partner_id.property_purchase_currency_id
|
||||
or self.env.context.get("default_currency_id")
|
||||
or self.env.company.currency_id
|
||||
or self.currency_id
|
||||
)
|
||||
|
||||
if self.partner_id and self.move_type in ['in_invoice', 'in_refund'] and self.currency_id != currency_id:
|
||||
|
||||
@@ -830,3 +830,33 @@ class TestInvoicePurchaseMatch(TestPurchaseToInvoiceCommon):
|
||||
|
||||
self.assertEqual(bill.currency_id, self.env.company.currency_id, "The currency of the Bill should be the same as the currency of the company")
|
||||
self.assertEqual(bill.invoice_line_ids.currency_id, self.env.company.currency_id, "The currency of the Bill lines should be the same as the currency of the company")
|
||||
|
||||
def test_onchange_partner_no_currency(self):
|
||||
"""
|
||||
Test that the currency of the Bill is correctly set when the partner is changed
|
||||
as well as the currency of the Bill lines even if the partner has no property_purchase_currency_id set
|
||||
"""
|
||||
|
||||
vendor_a = self.env['res.partner'].create({
|
||||
'name': 'Vendor A with No Currency',
|
||||
})
|
||||
vendor_b = self.env['res.partner'].create({
|
||||
'name': 'Vendor B with No Currency',
|
||||
})
|
||||
|
||||
move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
|
||||
move_form.partner_id = vendor_a
|
||||
move_form.currency_id = self.env.ref('base.EUR')
|
||||
with move_form.invoice_line_ids.new() as line_form:
|
||||
line_form.product_id = self.product_order
|
||||
line_form.quantity = 1
|
||||
bill = move_form.save()
|
||||
|
||||
self.assertEqual(bill.currency_id, self.env.ref('base.EUR'), "The currency of the Bill should be the one set on the Bill")
|
||||
self.assertEqual(bill.invoice_line_ids.currency_id, self.env.ref('base.EUR'), "The currency of the Bill lines should be the same as the currency of the Bill")
|
||||
|
||||
move_form.partner_id = vendor_b
|
||||
bill = move_form.save()
|
||||
|
||||
self.assertEqual(bill.currency_id, self.env.ref('base.EUR'), "The currency of the Bill should be the one set on the Bill")
|
||||
self.assertEqual(bill.invoice_line_ids.currency_id, self.env.ref('base.EUR'), "The currency of the Bill lines should be the same as the currency of the Bill")
|
||||
|
||||
Reference in New Issue
Block a user