Bug
This commit is contained in:
@@ -1119,8 +1119,9 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
return line.move.id
|
return line.move.id
|
||||||
|
|
||||||
def get_rate(self,name=None):
|
def get_rate(self,name=None):
|
||||||
if self.amount_second_currency:
|
amount = self.credit if self.credit else self.debit
|
||||||
return round((self.credit if self.credit else self.debit) / abs(self.amount_second_currency),6)
|
if self.amount_second_currency and amount:
|
||||||
|
return round(abs(self.amount_second_currency) / amount, 6)
|
||||||
|
|
||||||
@fields.depends(
|
@fields.depends(
|
||||||
'debit', 'credit',
|
'debit', 'credit',
|
||||||
@@ -1163,7 +1164,14 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView):
|
|||||||
if not self.rate:
|
if not self.rate:
|
||||||
self.rate = self._get_second_currency_rate()
|
self.rate = self._get_second_currency_rate()
|
||||||
if self.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:
|
if self.amount_second_currency > 0:
|
||||||
self.debit = amount
|
self.debit = amount
|
||||||
self.credit = Decimal(0)
|
self.credit = Decimal(0)
|
||||||
|
|||||||
@@ -599,10 +599,10 @@ class AccountTestCase(
|
|||||||
amount_second_currency=Decimal('100.00'))
|
amount_second_currency=Decimal('100.00'))
|
||||||
line.on_change_amount_second_currency()
|
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.credit, Decimal(0))
|
||||||
self.assertEqual(line.rate, Decimal('0.939506'))
|
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(
|
line = Line(
|
||||||
account=expense,
|
account=expense,
|
||||||
@@ -612,16 +612,16 @@ class AccountTestCase(
|
|||||||
line.on_change_amount_second_currency()
|
line.on_change_amount_second_currency()
|
||||||
|
|
||||||
self.assertEqual(line.debit, Decimal(0))
|
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.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.debit = line.credit = Decimal(0)
|
||||||
line.rate = Decimal('1.100000')
|
line.rate = Decimal('1.100000')
|
||||||
line.on_change_rate()
|
line.on_change_rate()
|
||||||
|
|
||||||
self.assertEqual(line.debit, Decimal(0))
|
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'))
|
self.assertEqual(line.rate, Decimal('1.100000'))
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
|
|||||||
@@ -1220,6 +1220,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
|||||||
line.amount_second_currency = (
|
line.amount_second_currency = (
|
||||||
line.amount_second_currency.copy_sign(
|
line.amount_second_currency.copy_sign(
|
||||||
line.debit - line.credit))
|
line.debit - line.credit))
|
||||||
|
line.rate = line.get_rate()
|
||||||
line.account = self.account
|
line.account = self.account
|
||||||
logger.info("_GET_MOVE_LINE_ACCOUNT:%s",line.account)
|
logger.info("_GET_MOVE_LINE_ACCOUNT:%s",line.account)
|
||||||
if self.account.party_required:
|
if self.account.party_required:
|
||||||
@@ -1990,6 +1991,10 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
|||||||
move_line_.account = gl.product.account_stock_in_used
|
move_line_.account = gl.product.account_stock_in_used
|
||||||
|
|
||||||
move_lines = [move_line,move_line_]
|
move_lines = [move_line,move_line_]
|
||||||
|
if move_line.amount_second_currency:
|
||||||
|
move_line.rate = move_line.get_rate()
|
||||||
|
if move_line_.amount_second_currency:
|
||||||
|
move_line_.rate = move_line_.get_rate()
|
||||||
|
|
||||||
if drop:
|
if drop:
|
||||||
drop_line = AccountMoveLine()
|
drop_line = AccountMoveLine()
|
||||||
@@ -2027,6 +2032,10 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
|||||||
drop_line_.second_currency = self.currency
|
drop_line_.second_currency = self.currency
|
||||||
drop_line_.amount_second_currency = -original_amount
|
drop_line_.amount_second_currency = -original_amount
|
||||||
move_lines = [drop_line,drop_line_]
|
move_lines = [drop_line,drop_line_]
|
||||||
|
if drop_line.amount_second_currency:
|
||||||
|
drop_line.rate = drop_line.get_rate()
|
||||||
|
if drop_line_.amount_second_currency:
|
||||||
|
drop_line_.rate = drop_line_.get_rate()
|
||||||
|
|
||||||
return move_lines
|
return move_lines
|
||||||
|
|
||||||
@@ -3262,6 +3271,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
|||||||
line.amount_second_currency = (
|
line.amount_second_currency = (
|
||||||
line.amount_second_currency.copy_sign(
|
line.amount_second_currency.copy_sign(
|
||||||
line.debit - line.credit))
|
line.debit - line.credit))
|
||||||
|
line.rate = line.get_rate()
|
||||||
line.account = self.account
|
line.account = self.account
|
||||||
logger.info("GET_MOVE_LINES_ACCOUNT:%s",line.account)
|
logger.info("GET_MOVE_LINES_ACCOUNT:%s",line.account)
|
||||||
if self.account.party_required:
|
if self.account.party_required:
|
||||||
@@ -3557,6 +3567,7 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
|
|||||||
line.amount_second_currency = (
|
line.amount_second_currency = (
|
||||||
line.amount_second_currency.copy_sign(
|
line.amount_second_currency.copy_sign(
|
||||||
line.debit - line.credit))
|
line.debit - line.credit))
|
||||||
|
line.rate = line.get_rate()
|
||||||
line.account = self.account
|
line.account = self.account
|
||||||
if self.account.party_required:
|
if self.account.party_required:
|
||||||
line.party = self.invoice.party
|
line.party = self.invoice.party
|
||||||
|
|||||||
Reference in New Issue
Block a user