This commit is contained in:
2026-04-28 11:51:07 +02:00
parent 257916bd6c
commit f6db19d1d9
3 changed files with 27 additions and 8 deletions

View File

@@ -1119,8 +1119,9 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
return line.move.id
def get_rate(self,name=None):
if self.amount_second_currency:
return round((self.credit if self.credit else self.debit) / abs(self.amount_second_currency),6)
amount = self.credit if self.credit else self.debit
if self.amount_second_currency and amount:
return round(abs(self.amount_second_currency) / amount, 6)
@fields.depends(
'debit', 'credit',
@@ -1163,7 +1164,14 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
if not self.rate:
self.rate = self._get_second_currency_rate()
if self.rate:
amount = round(self.rate * abs(self.amount_second_currency), 2)
company_currency = (
self.company.currency if getattr(self, 'company', None)
else self.account.company.currency
if getattr(self, 'account', None) else None)
if not company_currency:
return
amount = company_currency.round(
abs(self.amount_second_currency) / self.rate)
if self.amount_second_currency > 0:
self.debit = amount
self.credit = Decimal(0)