[FIX] purchase: prevent traceback onchange partner
Steps to reproduce: In an account move, if the partner_id is changed to one that does not have a value assigned in the property_purchase_currency_id field and with a value in the context for default_currency_id, when passing through the _onchange_partner_id function of the purchase module, Cause: the variable currency_id will take the value in the context as second option causing an error when trying to get the value in currency_id.id because currency_id will be an integer and not a record. issue-121232 note fw 16: The record must be saved in order to trigger the compute in https://github.com/odoo/odoo/blob/5a256af35e5d612efed9ed8af1cf23fd62bd83f4/addons/account/models/account_move_line.py#L449-L457 in order to recompute the currency of the lines closes odoo/odoo#122075 X-original-commit: d0109dc5d7b0012ad1a4c45e5204934ae481779b Signed-off-by: Yolann Sabaux (yosa) <yosa@odoo.com>
This commit is contained in:
@@ -86,7 +86,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['res.currency'].browse(self.env.context.get("default_currency_id"))
|
||||
or self.currency_id
|
||||
)
|
||||
|
||||
|
||||
@@ -835,6 +835,7 @@ class TestInvoicePurchaseMatch(TestPurchaseToInvoiceCommon):
|
||||
"""
|
||||
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
|
||||
or when and the `default_currency_id` is defined in the context
|
||||
"""
|
||||
|
||||
vendor_a = self.env['res.partner'].create({
|
||||
@@ -844,7 +845,8 @@ class TestInvoicePurchaseMatch(TestPurchaseToInvoiceCommon):
|
||||
'name': 'Vendor B with No Currency',
|
||||
})
|
||||
|
||||
move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
|
||||
ctx = {'default_move_type': 'in_invoice'}
|
||||
move_form = Form(self.env['account.move'].with_context(ctx))
|
||||
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:
|
||||
@@ -860,3 +862,17 @@ class TestInvoicePurchaseMatch(TestPurchaseToInvoiceCommon):
|
||||
|
||||
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")
|
||||
|
||||
ctx['default_currency_id'] = self.currency_data['currency'].id
|
||||
move_form_currency_in_context = Form(self.env['account.move'].with_context(ctx))
|
||||
move_form_currency_in_context.currency_id = self.env.ref('base.EUR')
|
||||
with move_form_currency_in_context.invoice_line_ids.new() as line_form:
|
||||
line_form.product_id = self.product_order
|
||||
line_form.quantity = 1
|
||||
move_form_currency_in_context.save()
|
||||
|
||||
move_form_currency_in_context.partner_id = vendor_a
|
||||
bill = move_form_currency_in_context.save()
|
||||
|
||||
self.assertEqual(bill.currency_id, self.currency_data['currency'], "The currency of the Bill should be the one of the context")
|
||||
self.assertEqual(bill.invoice_line_ids.currency_id, self.currency_data['currency'], "The currency of the Bill lines should be the same as the currency of the Bill")
|
||||
|
||||
Reference in New Issue
Block a user