Skip to content

Commit

Permalink
[ADD] compute change
Browse files Browse the repository at this point in the history
  • Loading branch information
luismalta committed Apr 29, 2020
1 parent 6e2fe0c commit 1f8213c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
31 changes: 31 additions & 0 deletions l10n_br_fiscal/models/document_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ def _compute_amount(self):
default=0.00,
compute="_compute_amount")

amount_change_value = fields.Monetary(
string="Change Value",
default=0.00,
compute="_compute_payment_change_value")

amount_payment_value = fields.Monetary(
string="Payment Value",
default=0.00,
compute="_compute_payment_change_value")

amount_missing_payment_value = fields.Monetary(
string="Missing Payment Value",
default=0.00,
compute="_compute_payment_change_value")

line_ids = fields.One2many(
comodel_name="l10n_br_fiscal.document.line.abstract",
inverse_name="document_id",
Expand Down Expand Up @@ -510,3 +525,19 @@ def _onchange_fiscal_payment_ids(self):
for line in payment.line_ids:
financial_ids.append(line.id)
self.financial_ids = [(6, 0, financial_ids)]

@api.depends("fiscal_payment_ids")
def _compute_payment_change_value(self):
payment_value = 0
for payment in self.fiscal_payment_ids:
for line in payment.line_ids:
payment_value += line.amount

self.amount_payment_value = payment_value

change_value = payment_value - self.amount_total
self.amount_change_value = change_value if change_value >= 0 else 0

missing_payment = self.amount_total - payment_value
self.amount_missing_payment_value = missing_payment \
if missing_payment >= 0 else 0
5 changes: 4 additions & 1 deletion l10n_br_fiscal/views/document_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,16 @@
<newline/>
</group>
<separator name="pagamentos" string="Pagamentos" colspan="4"/>
<field name="amount_missing_payment_value" invisible="1"/>
<field name="fiscal_payment_ids" context="{
'default_amount': amount_total,
'default_amount': amount_missing_payment_value,
'default_date': date,
'default_currency_id': currency_id,
'default_company_id': company_id,
'default_document_id': active_id,
}" nolabel="1"/>
<label for="" string="Troco"/>
<field name="amount_change_value"/>
<separator name="financial" string="Financeiro" colspan="4"/>
<field name="financial_ids" nolabel="1" context="{
'default_document_id': active_id,
Expand Down

0 comments on commit 1f8213c

Please sign in to comment.