Skip to content

Commit

Permalink
[FIX]account_banking_ach_discount: fix manual discount case
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip Mangukiya committed Mar 2, 2022
1 parent be607a9 commit df43dc3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
59 changes: 41 additions & 18 deletions account_banking_ach_discount/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ def _prepare_move(self, bank_lines=None):
amount = line.amount_currency
discount = line.discount_amount
payment_difference = line.payment_difference
writeoff = (
payment_difference and payment_difference - discount or 0.0
)
invoice_close = line.payment_difference_handling != "open"
writeoff = 0.0
invoice_close = False
if payment_difference:
writeoff = (
payment_difference and payment_difference - discount or 0.0
)
invoice_close = line.payment_difference_handling != "open"
use_debit = line.move_id.move_type in (
"in_invoice",
"out_refund",
Expand All @@ -39,21 +42,41 @@ def _prepare_move(self, bank_lines=None):
line_ids.append((0, 0, temp_vals))

if discount > 0:
discount_information = line.move_id.invoice_payment_term_id._check_payment_term_discount(
line.move_id, line.date
)
discount_vals = temp_vals.copy()
discount_vals["account_id"] = discount_information[1]
discount_vals["name"] = "Early Pay Discount"
if use_debit:
discount_vals["debit"] = 0.0
discount_vals["credit"] = discount_information[0]
if payment_difference:
discount_information = line.move_id.invoice_payment_term_id._check_payment_term_discount(
line.move_id, line.date
)
discount_vals = temp_vals.copy()
discount_vals["account_id"] = discount_information[1]
discount_vals["name"] = "Early Pay Discount"
if use_debit:
discount_vals["debit"] = 0.0
discount_vals["credit"] = discount_information[0]
else:
discount_vals["credit"] = 0.0
discount_vals["debit"] = discount_information[0]
discount_vals["bank_payment_line_id"] = False
if discount_vals:
line_ids.append((0, 0, discount_vals))
# Discount Taken Update
line.move_id.discount_taken = discount
else:
discount_vals["credit"] = 0.0
discount_vals["debit"] = discount_information[0]
discount_vals["bank_payment_line_id"] = False
if discount_vals:
line_ids.append((0, 0, discount_vals))
#Case: If user Manually enters discount amount
discount_vals = temp_vals.copy()
discount_vals["account_id"] = line.writeoff_account_id and line.writeoff_account_id.id or False
discount_vals["name"] = "Early Pay Discount"
if use_debit:
discount_vals["debit"] = 0.0
discount_vals["credit"] = discount
else:
discount_vals["credit"] = 0.0
discount_vals["debit"] = discount
discount_vals["bank_payment_line_id"] = False
if discount_vals:
line_ids.append((0, 0, discount_vals))
# Discount Taken Update
line.move_id.discount_taken = discount


if invoice_close and round(writeoff, 2):
if use_debit:
Expand Down
12 changes: 0 additions & 12 deletions account_banking_ach_discount/models/bank_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,3 @@ def _compute_discount_amount(self):
for bline in self:
discount_amount = sum(bline.mapped("payment_line_ids.discount_amount"))
bline.discount_amount = discount_amount

# def reconcile(self):
# self.ensure_one()
# amlo = self.env["account.move.line"]
# transit_mlines = amlo.search([("bank_payment_line_id", "=", self.id)])
# for line in transit_mlines:
# ap_mlines = line.move_id.line_ids.filtered(
# lambda x: x.account_id == line.account_id
# )
# lines_to_rec = line
# lines_to_rec += ap_mlines
# lines_to_rec.reconcile()
13 changes: 6 additions & 7 deletions account_banking_ach_discount/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<field name="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount" />
<field name="writeoff_account_id" string="Discount Account"/>
<field name="total_amount" />
</field>
</field>
Expand All @@ -25,14 +26,12 @@
/>
<field name="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount" />
<field name="payment_difference" />
<field name="total_amount" />
<field name="payment_difference_handling" />
<field name="writeoff_account_id" />
<field name="reason_code" />
<field name="note" />
<field name="move_id" />
<field name="discount_amount" />
<field name="writeoff_account_id" string="Discount Account"/>
<field name="reason_code" optional="hide"/>
<field name="note" optional="hide"/>
<field name="move_id" optional="hide"/>
</field>
</field>
</record>
Expand Down

0 comments on commit df43dc3

Please sign in to comment.