Skip to content

Commit

Permalink
[FIX] Corrected currency assignment for multi-company instances with …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
baptiste-n42 committed Jun 10, 2024
1 parent e4ea956 commit cfbcd57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions hr_contract_currency/models/hr_contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
# Copyright 2020 Onestein (<https://www.onestein.eu>)
# Copyright 2024 Newlogic (<https://www.newlogic.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
Expand All @@ -14,12 +15,18 @@ class HrContract(models.Model):
readonly=False,
required=True,
default=lambda self: self._get_default_currency_id(),
compute="_compute_currency_id",
tracking=True,
store=True,
)

def _get_default_currency_id(self):
return self.company_id.currency_id or self.env.company.currency_id

def _compute_currency_id(self):
for rec in self:
rec.currency_id = rec.company_id.currency_id

@api.model
def create(self, vals):
if vals.get("company_id") and not vals.get("currency_id"):
Expand Down
12 changes: 10 additions & 2 deletions hr_contract_currency/views/hr_contract.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
Copyright 2024 Newlogic (https://newlogic.com)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="hr_contract_view_form" model="ir.ui.view">
<field name="model">hr.contract</field>
<field name="inherit_id" ref="hr_contract.hr_contract_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='wage']" position='after'>
<field name="currency_id" groups="base.group_multi_currency" />
<xpath expr="//group[@name='salary']" position='after'>
<group name="salary_currency">
<field
name="currency_id"
string="Currency"
options="{'no_create': True}"
groups="base.group_multi_currency"
/>
</group>
</xpath>
</field>
</record>
Expand Down

0 comments on commit cfbcd57

Please sign in to comment.