Skip to content

Commit

Permalink
fix partial reconciliation with refunds
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow authored and AdriaGForgeFlow committed Sep 9, 2019
1 parent e9b3c00 commit 6838301
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions account_check_report/report/report_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ def _format_date_to_partner_lang(self, str_date, partner_id):
return date.strftime(lang.date_format)

def _get_paid_lines(self, payment):
pay_acc = payment.journal_id.default_debit_account_id or \
payment.journal_id.default_credit_account_id
rec_lines = payment.move_line_ids.filtered(
lambda x: x.account_id.reconcile and x.account_id != pay_acc)
lambda x: x.account_id.reconcile and x.account_id ==
payment.destination_account_id
and x.partner_id == payment.partner_id)
amls = rec_lines.mapped('matched_credit_ids.credit_move_id') + \
rec_lines.mapped('matched_debit_ids.debit_move_id')
amls -= rec_lines
# Here we need to handle a nasty corner case.
# Sometimes we match a payment with invoices and refunds. Internally
# Odoo will match some invoices with their refunds, and not with the
# payment, so the payment move line is not linked with those matches
# invoices and refunds. But the end user was not really aware of this
# as he probably just selected a bunch of invoices and refunds and made
# a payment, assuming that the payment will correctly reflect the
# refunds. In order to solve that, we will just include all the move
# lines associated to the invoices that the user intended to pay,
# including refunds.
invoice_amls = payment.invoice_ids.mapped('move_id.line_ids').filtered(
lambda x: x.account_id.reconcile
and x.account_id == payment.destination_account_id
and x.partner_id == payment.partner_id)
amls |= invoice_amls
return amls

def _get_residual_amount(self, payment, line):
Expand All @@ -43,11 +58,15 @@ def _get_paid_amount(self, payment, line):
total_amount_to_show = 0.0
# We pay out
if line.matched_credit_ids:
amount = sum([p.amount for p in line.matched_credit_ids])
amount = -1 * sum([p.amount for p in line.matched_credit_ids])
# We receive payment
elif line.matched_debit_ids:
amount = sum([p.amount for p in line.matched_debit_ids])

# In case of customer payment, we reverse the amounts
if payment.partner_type == 'customer':
amount *= -1

amount_to_show = \
payment.company_id.currency_id.with_context(
date=payment.payment_date).compute(
Expand Down

0 comments on commit 6838301

Please sign in to comment.