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)

View File

@@ -599,10 +599,10 @@ class AccountTestCase(
amount_second_currency=Decimal('100.00'))
line.on_change_amount_second_currency()
self.assertEqual(line.debit, Decimal('93.95'))
self.assertEqual(line.debit, Decimal('106.44'))
self.assertEqual(line.credit, Decimal(0))
self.assertEqual(line.rate, Decimal('0.939506'))
self.assertEqual(line.get_rate(), Decimal('0.939500'))
self.assertEqual(line.get_rate(), Decimal('0.939496'))
line = Line(
account=expense,
@@ -612,16 +612,16 @@ class AccountTestCase(
line.on_change_amount_second_currency()
self.assertEqual(line.debit, Decimal(0))
self.assertEqual(line.credit, Decimal('101.56'))
self.assertEqual(line.credit, Decimal('115.06'))
self.assertEqual(line.rate, Decimal('0.939506'))
self.assertEqual(line.get_rate(), Decimal('0.939500'))
self.assertEqual(line.get_rate(), Decimal('0.939510'))
line.debit = line.credit = Decimal(0)
line.rate = Decimal('1.100000')
line.on_change_rate()
self.assertEqual(line.debit, Decimal(0))
self.assertEqual(line.credit, Decimal('118.91'))
self.assertEqual(line.credit, Decimal('98.27'))
self.assertEqual(line.rate, Decimal('1.100000'))
@with_transaction()