This commit is contained in:
2026-04-28 11:57:28 +02:00
parent f6db19d1d9
commit 3314d31fcd

View File

@@ -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: