Skip to content

Commit

Permalink
[IMP] account: show payments on invoice report.
Browse files Browse the repository at this point in the history
Each time the invoice is printed, it shows an updated remaining amount on the invoice. The first print, though, is kept as canonical reference as attachment.

Was PR#16343
  • Loading branch information
smetl authored and qdp-odoo committed Jun 28, 2017
1 parent 8e230ae commit 09296e7
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 222 deletions.
87 changes: 51 additions & 36 deletions addons/account/models/account_invoice.py
Expand Up @@ -146,47 +146,62 @@ def _get_outstanding_info_JSON(self):
self.outstanding_credits_debits_widget = json.dumps(info)
self.has_outstanding = True

@api.model
def _get_payments_vals(self):
if not self.payment_move_line_ids:
return []
payment_vals = []
currency_id = self.currency_id
for payment in self.payment_move_line_ids:
payment_currency_id = False
if self.type in ('out_invoice', 'in_refund'):
amount = sum([p.amount for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids])
amount_currency = sum(
[p.amount_currency for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids])
if payment.matched_debit_ids:
payment_currency_id = all([p.currency_id == payment.matched_debit_ids[0].currency_id for p in
payment.matched_debit_ids]) and payment.matched_debit_ids[
0].currency_id or False
elif self.type in ('in_invoice', 'out_refund'):
amount = sum(
[p.amount for p in payment.matched_credit_ids if p.credit_move_id in self.move_id.line_ids])
amount_currency = sum([p.amount_currency for p in payment.matched_credit_ids if
p.credit_move_id in self.move_id.line_ids])
if payment.matched_credit_ids:
payment_currency_id = all([p.currency_id == payment.matched_credit_ids[0].currency_id for p in
payment.matched_credit_ids]) and payment.matched_credit_ids[
0].currency_id or False
# get the payment value in invoice currency
if payment_currency_id and payment_currency_id == self.currency_id:
amount_to_show = amount_currency
else:
amount_to_show = payment.company_id.currency_id.with_context(date=payment.date).compute(amount,
self.currency_id)
if float_is_zero(amount_to_show, precision_rounding=self.currency_id.rounding):
continue
payment_ref = payment.move_id.name
if payment.move_id.ref:
payment_ref += ' (' + payment.move_id.ref + ')'
payment_vals.append({
'name': payment.name,
'journal_name': payment.journal_id.name,
'amount': amount_to_show,
'currency': currency_id.symbol,
'digits': [69, currency_id.decimal_places],
'position': currency_id.position,
'date': payment.date,
'payment_id': payment.id,
'move_id': payment.move_id.id,
'ref': payment_ref,
})
return payment_vals

@api.one
@api.depends('payment_move_line_ids.amount_residual')
def _get_payment_info_JSON(self):
self.payments_widget = json.dumps(False)
if self.payment_move_line_ids:
info = {'title': _('Less Payment'), 'outstanding': False, 'content': []}
currency_id = self.currency_id
for payment in self.payment_move_line_ids:
payment_currency_id = False
if self.type in ('out_invoice', 'in_refund'):
amount = sum([p.amount for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids])
amount_currency = sum([p.amount_currency for p in payment.matched_debit_ids if p.debit_move_id in self.move_id.line_ids])
if payment.matched_debit_ids:
payment_currency_id = all([p.currency_id == payment.matched_debit_ids[0].currency_id for p in payment.matched_debit_ids]) and payment.matched_debit_ids[0].currency_id or False
elif self.type in ('in_invoice', 'out_refund'):
amount = sum([p.amount for p in payment.matched_credit_ids if p.credit_move_id in self.move_id.line_ids])
amount_currency = sum([p.amount_currency for p in payment.matched_credit_ids if p.credit_move_id in self.move_id.line_ids])
if payment.matched_credit_ids:
payment_currency_id = all([p.currency_id == payment.matched_credit_ids[0].currency_id for p in payment.matched_credit_ids]) and payment.matched_credit_ids[0].currency_id or False
# get the payment value in invoice currency
if payment_currency_id and payment_currency_id == self.currency_id:
amount_to_show = amount_currency
else:
amount_to_show = payment.company_id.currency_id.with_context(date=payment.date).compute(amount, self.currency_id)
if float_is_zero(amount_to_show, precision_rounding=self.currency_id.rounding):
continue
payment_ref = payment.move_id.name
if payment.move_id.ref:
payment_ref += ' (' + payment.move_id.ref + ')'
info['content'].append({
'name': payment.name,
'journal_name': payment.journal_id.name,
'amount': amount_to_show,
'currency': currency_id.symbol,
'digits': [69, currency_id.decimal_places],
'position': currency_id.position,
'date': payment.date,
'payment_id': payment.id,
'move_id': payment.move_id.id,
'ref': payment_ref,
})
info = {'title': _('Less Payment'), 'outstanding': False, 'content': self._get_payments_vals()}
self.payments_widget = json.dumps(info)

@api.one
Expand Down
33 changes: 16 additions & 17 deletions addons/account/views/account_report.xml
Expand Up @@ -7,9 +7,8 @@
model="account.invoice"
string="Invoices"
report_type="qweb-pdf"
name="account.report_invoice"
file="account.report_invoice"
attachment_use="True"
name="account.report_invoice_with_payments"
file="account.report_invoice_with_payments"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(
object.type == 'out_invoice' and object.state == 'draft' and 'Draft Invoice' or
Expand All @@ -22,23 +21,23 @@
object.type == 'in_refund' and 'Vendor Credit Note - %s' % (object.number))"
/>

<report
id="account_invoice_action_report_duplicate"
<report
id="account_invoices_without_payment"
model="account.invoice"
string="Duplicates"
string="Invoices without Payment"
report_type="qweb-pdf"
name="account.account_invoice_report_duplicate_main"
file="account.report_invoice_duplicate"
attachment_use="False"
name="account.report_invoice"
file="account.report_invoice"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(
object.type == 'out_invoice' and object.state == 'draft' and 'Duplicate Invoice' or
object.type == 'out_invoice' and object.state in ('open','paid') and 'Duplicate Invoice - %s' % (object.number) or
object.type == 'out_refund' and object.state == 'draft' and 'Duplicate Credit Note' or
object.type == 'out_refund' and 'Duplicate Credit Note - %s' % (object.number) or
object.type == 'in_invoice' and object.state == 'draft' and 'Duplicate Vendor Bill' or
object.type == 'in_invoice' and object.state in ('open','paid') and 'Duplicate Vendor Bill - %s' % (object.number) or
object.type == 'in_refund' and object.state == 'draft' and 'Duplicate Vendor Credit Note' or
object.type == 'in_refund' and 'Duplicate Vendor Credit Note - %s' % (object.number))"
object.type == 'out_invoice' and object.state == 'draft' and 'Draft Invoice' or
object.type == 'out_invoice' and object.state in ('open','paid') and 'Invoice - %s' % (object.number) or
object.type == 'out_refund' and object.state == 'draft' and 'Credit Note' or
object.type == 'out_refund' and 'Credit Note - %s' % (object.number) or
object.type == 'in_invoice' and object.state == 'draft' and 'Vendor Bill' or
object.type == 'in_invoice' and object.state in ('open','paid') and 'Vendor Bill - %s' % (object.number) or
object.type == 'in_refund' and object.state == 'draft' and 'Vendor Credit Note' or
object.type == 'in_refund' and 'Vendor Credit Note - %s' % (object.number))"
/>

<report
Expand Down

0 comments on commit 09296e7

Please sign in to comment.