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 e312381
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 15 additions & 7 deletions hr_contract_currency/models/hr_contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 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
from odoo import fields, models


class HrContract(models.Model):
Expand All @@ -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
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 e312381

Please sign in to comment.