Skip to content

Commit

Permalink
[FIX] Fix the issue allowed tho pay non ACH IN/OUT payment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murtaza-OSI committed Sep 30, 2021
1 parent 8da666a commit 5fbcc95
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 53 deletions.
70 changes: 38 additions & 32 deletions account_banking_ach_discount/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,46 @@ class AccountPayment(models.Model):
_inherit = "account.payment"

def action_validate_invoice_payment(self):
if any(len(record.reconciled_invoice_ids) != 1 for record in self):
# For multiple invoices, there is account.register.payments wizard
raise UserError(
_(
"This method should only be called to process a "
"single invoice's payment."
# Check if Invoices have ACH IN/OUT payment method, to avoid any
# conflict
valid = False
if self.filtered(lambda p: p.payment_method_id.code in ("ACH-In", "ACH-Out")):
valid = True
if any(len(record.invoice_ids) != 1 for record in self):
# For multiple invoices, there is account.register.payments wizard
raise UserError(
_(
"This method should only be called to process a "
"single invoice's payment."
)
)
)
for payment in self:
payment_method = payment.payment_method_id
if payment_method:
if payment_method.code in ("ACH-In", "ACH-Out"):
# Update invoice with Payment mode
if not payment.reconciled_invoice_ids.payment_mode_id:
payment_mode_id = self.env["account.payment.mode"].search(
[
("payment_type", "=", payment.payment_type),
("payment_method_id", "=", payment_method.id),
("payment_order_ok", "=", True),
],
limit=1,
)
if payment_mode_id:
payment.reconciled_invoice_ids.write(
{"payment_mode_id": payment_mode_id.id}
)
payment.reconciled_invoice_ids.move_id.line_ids.write(
{"payment_mode_id": payment_mode_id.id}
if valid:
for payment in self:
payment_method = payment.payment_method_id
if payment_method:
if payment_method.code in ("ACH-In", "ACH-Out"):
# Update invoice with Payment mode
if not payment.reconciled_invoice_ids.payment_mode_id:
payment_mode_id = self.env["account.payment.mode"].search(
[
("payment_type", "=", payment.payment_type),
("payment_method_id", "=", payment_method.id),
("payment_order_ok", "=", True),
],
limit=1,
)
action = (
payment.reconciled_invoice_ids.create_account_payment_line()
)
payment.unlink()
return action
if payment_mode_id:
payment.reconciled_invoice_ids.write(
{"payment_mode_id": payment_mode_id.id}
)
payment.reconciled_invoice_ids.move_id.line_ids.write(
{"payment_mode_id": payment_mode_id.id}
)
action = (
payment.reconciled_invoice_ids.create_account_payment_line()
)
payment.unlink()
return action
res = super(AccountPayment, self).action_validate_invoice_payment()
return res

Expand Down
3 changes: 1 addition & 2 deletions account_banking_ach_discount/models/bank_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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"]
Expand All @@ -36,4 +36,3 @@ def reconcile(self):
lines_to_rec = line
lines_to_rec += ap_mlines
lines_to_rec.reconcile()

44 changes: 25 additions & 19 deletions account_banking_ach_discount/views/account_payment_view.xml
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
<?xml version="1.0"?>
<?xml version="1.0" ?>
<odoo>

<record id="account_payment_line_discount_amount_form" model="ir.ui.view">
<field name="name">account.payment.line.form</field>
<field name="model">account.payment.line</field>
<field name="inherit_id" ref="account_payment_order.account_payment_line_form"/>
<field
name="inherit_id"
ref="account_payment_order.account_payment_line_form"
/>
<field name="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount"/>
<field name="total_amount"/>
<field name="discount_amount" />
<field name="total_amount" />
</field>
</field>
</record>

<record id="account_payment_line_discount_amount_tree" model="ir.ui.view">
<field name="name">account.payment.line.tree</field>
<field name="model">account.payment.line</field>
<field name="inherit_id" ref="account_payment_order.account_payment_line_tree"/>
<field
name="inherit_id"
ref="account_payment_order.account_payment_line_tree"
/>
<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="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>
</field>
</record>

<record id="bank_payment_line_discount_amount_form" model="ir.ui.view">
<field name="name">banking.bank.payment.line.form</field>
<field name="model">bank.payment.line</field>
<field name="inherit_id" ref="account_payment_order.bank_payment_line_form"/>
<field name="inherit_id" ref="account_payment_order.bank_payment_line_form" />
<field name="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount"/>
<field name="total_amount"/>
<field name="discount_amount" />
<field name="total_amount" />
</field>
</field>
</record>

<record id="bank_payment_line_discount_amount_tree" model="ir.ui.view">
<field name="name">banking.bank.payment.line.tree</field>
<field name="model">bank.payment.line</field>
<field name="inherit_id" ref="account_payment_order.bank_payment_line_tree"/>
<field name="inherit_id" ref="account_payment_order.bank_payment_line_tree" />
<field name="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount"/>
<field name="total_amount"/>
<field name="discount_amount" />
<field name="total_amount" />
</field>
</field>
</record>
Expand Down

0 comments on commit 5fbcc95

Please sign in to comment.