From e31238187eb5626112e87e6109d75b8a9740be29 Mon Sep 17 00:00:00 2001 From: Baptiste Pellarin Date: Mon, 10 Jun 2024 11:18:19 +0700 Subject: [PATCH] [FIX] Corrected currency assignment for multi-company instances with varying currencies. Previously, Odoo defaulted to the currency of the first company when updating existing records. This issue has been addressed by utilizing a computed field. The `currency_id` field was being cut off at a 120% zoom level. By assigning the field to its own group, this display issue has been resolved without impacting user experience. --- hr_contract_currency/models/hr_contract.py | 22 +++++++++++++++------- hr_contract_currency/views/hr_contract.xml | 12 ++++++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/hr_contract_currency/models/hr_contract.py b/hr_contract_currency/models/hr_contract.py index 3d9c19ca5a06..653e6b7d186d 100644 --- a/hr_contract_currency/models/hr_contract.py +++ b/hr_contract_currency/models/hr_contract.py @@ -1,8 +1,9 @@ # Copyright 2018 Brainbean Apps (https://brainbeanapps.com) # Copyright 2020 Onestein () +# Copyright 2024 Newlogic () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class HrContract(models.Model): @@ -14,15 +15,22 @@ class HrContract(models.Model): readonly=False, required=True, default=lambda self: self._get_default_currency_id(), + compute="_compute_currency_id", + inverse="_inverse_currency_id", tracking=True, + store=True, ) def _get_default_currency_id(self): return self.company_id.currency_id or self.env.company.currency_id - @api.model - def create(self, vals): - if vals.get("company_id") and not vals.get("currency_id"): - company = self.env["res.company"].browse(vals.get("company_id")) - vals["currency_id"] = company.currency_id.id - return super().create(vals) + def _compute_currency_id(self): + for rec in self: + rec.currency_id = rec.company_id.currency_id + + def _inverse_currency_id(self): + for rec in self: + if not rec.currency_id: + rec.currency_id = rec.company_id.currency_id + else: + rec.currency_id = rec.currency_id diff --git a/hr_contract_currency/views/hr_contract.xml b/hr_contract_currency/views/hr_contract.xml index c3025132331c..bf9e54254097 100644 --- a/hr_contract_currency/views/hr_contract.xml +++ b/hr_contract_currency/views/hr_contract.xml @@ -1,6 +1,7 @@ @@ -8,8 +9,15 @@ hr.contract - - + + + +