From 3314d31fcd1c9ea5e31a7ff5319d240084d502d8 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Tue, 28 Apr 2026 11:57:28 +0200 Subject: [PATCH] Bug --- modules/account/move.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/account/move.py b/modules/account/move.py index 5ae5f00..1c4c6d5 100755 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -1126,7 +1126,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): @fields.depends( 'debit', 'credit', 'date','second_currency','amount_second_currency', 'rate', - 'origin', 'move_origin', 'move', '_parent_move.origin') + 'origin', 'move_origin', 'move', '_parent_move.origin', + 'company', 'account') def on_change_second_currency(self): if self._manual_rate_mode(): self.rate = self._get_second_currency_rate() @@ -1135,7 +1136,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): @fields.depends( 'debit', 'credit', 'date','second_currency','amount_second_currency', 'rate', - 'origin', 'move_origin', 'move', '_parent_move.origin') + 'origin', 'move_origin', 'move', '_parent_move.origin', + 'company', 'account') def on_change_rate(self): if self._manual_rate_mode() and not self.debit and not self.credit: self._compute_amount_from_second_currency() @@ -1159,15 +1161,23 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): rates = Currency._get_rate([self.second_currency], tdate) return rates.get(self.second_currency.id) if rates else None + def _get_company_currency(self): + Company = Pool().get('company.company') + for record in (self, getattr(self, 'move', None), + getattr(self, 'account', None)): + company = getattr(record, 'company', None) + if company: + return company.currency + company_id = Transaction().context.get('company') + if company_id: + return Company(company_id).currency + def _compute_amount_from_second_currency(self): if self.second_currency is not None and self.amount_second_currency is not None: if not self.rate: self.rate = self._get_second_currency_rate() if self.rate: - company_currency = ( - self.company.currency if getattr(self, 'company', None) - else self.account.company.currency - if getattr(self, 'account', None) else None) + company_currency = self._get_company_currency() if not company_currency: return amount = company_currency.round( @@ -1258,7 +1268,8 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): @fields.depends( 'amount_second_currency', 'debit', 'credit', 'date', 'second_currency', - 'rate', 'origin', 'move_origin', 'move', '_parent_move.origin') + 'rate', 'origin', 'move_origin', 'move', '_parent_move.origin', + 'company', 'account') def on_change_amount_second_currency(self): if self._manual_rate_mode(): if not self.rate: