Skip to content

Commit

Permalink
[FIX] account_index_based_currency: Transaction Amount is field compu…
Browse files Browse the repository at this point in the history
…ted from the agreement rate (#1320)

* [FIX] Transaction Amount is field computed from the agreement rate and amount.
Agreement amount is no longer a computed amount.
  • Loading branch information
hbto authored and moylop260 committed Dec 12, 2018
1 parent 829dffa commit 1ded20a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions account_index_based_currency/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,14 @@ def _compute_currency_amount(self):
inv.amount_total_signed, inv.index_based_currency_id,
inv.company_id, inv.date_invoice or fields.Date.today())
inv.index_based_currency_amount = index_based_currency_amount
inv.agreement_currency_amount = (
inv.index_based_currency_amount /
(inv.agreement_currency_rate or 1.0))
inv.transaction_currency_amount = (
inv.agreement_currency_rate * inv.agreement_currency_amount)

@api.onchange('agreement_currency_rate')
def onchange_agreement_currency_rate(self):
if self.agreement_currency_rate <= 0:
raise UserError(_('Invalid currency rate value'))

@api.onchange('agreement_currency_id')
def onchange_agreement_currency_id(self):
cur_obj = self.env['res.currency']
self.agreement_currency_rate = cur_obj._get_conversion_rate(
self.agreement_currency_id, self.index_based_currency_id,
self.company_id, self.date_invoice or fields.Date.today())
self.agreement_currency_amount = (
self.index_based_currency_amount * self.agreement_currency_rate)

@api.model
def default_get(self, default_fields):
res = super(AccountInvoice, self).default_get(default_fields)
Expand Down Expand Up @@ -75,9 +65,14 @@ def default_get(self, default_fields):
copy=False,
help="Total amount in the currency of the company, negative for "
"credit notes.")
transaction_currency_amount = fields.Monetary(
currency_field='currency_id',
copy=False,
store=True, compute='_compute_currency_amount',
help="Total amount in the currency of the transaction in accordance "
"with the agreement amount and rate.")
agreement_currency_amount = fields.Monetary(
currency_field='agreement_currency_id',
store=True, compute='_compute_currency_amount',
copy=False,
help="Total amount in the currency of the company, negative for "
"credit notes.")
Expand All @@ -93,6 +88,7 @@ def default_get(self, default_fields):
copy=False, digits=(12, 6))
agreement_currency_rate = fields.Float(
help="Currency rate this Document was agreed",
default=1,
readonly=True, states={'draft': [('readonly', False)]},
copy=True, digits=(12, 6))

Expand Down
2 changes: 1 addition & 1 deletion account_index_based_currency/views/invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</group>
<group colspan="2">
<field name="index_based_currency_amount" string="Index Based Amount"/>
<field name="amount_total_signed" string="Transaction Amount"/>
<field name="transaction_currency_amount" string="Transaction Amount"/>
<field name="amount_total_company_signed" string="Company Amount"/>
<field name="agreement_currency_amount" string="Agreement Amount"/>
</group>
Expand Down

0 comments on commit 1ded20a

Please sign in to comment.