Skip to content
Snippets Groups Projects
Commit da6724e3 authored by Yolann Sabaux's avatar Yolann Sabaux
Browse files

[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

closes odoo/odoo#121921

X-original-commit: e04d4a0b
Signed-off-by: default avatarYolann Sabaux (yosa) <yosa@odoo.com>
Signed-off-by: default avatarAdrien Widart (awt) <awt@odoo.com>
parent 5caec324
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,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
)
......
......@@ -665,6 +665,7 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
"""
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({
......@@ -674,7 +675,8 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
'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:
......@@ -690,3 +692,15 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
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.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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment