Skip to content

Commit

Permalink
[MIG] account_banking_ach_discount: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow committed Oct 20, 2023
1 parent 5775f86 commit ef21873
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 247 deletions.
2 changes: 1 addition & 1 deletion account_banking_ach_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Discount on ACH batch payments",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Accounting",
Expand Down
3 changes: 1 addition & 2 deletions account_banking_ach_discount/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_payment
from . import account_move_line
from . import bank_payment_line
from . import account_payment_order
from . import account_move
from . import account_payment_line
116 changes: 30 additions & 86 deletions account_banking_ach_discount/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,43 @@
class AccountMove(models.Model):
_inherit = "account.move"

def _get_reconciled_info_JSON_values(self):
res = super(AccountMove, self)._get_reconciled_info_JSON_values()
inv_number = self.ref
if res:
flag = False
for item in res:
def _compute_payments_widget_reconciled_info(self):
res = super(AccountMove, self)._compute_payments_widget_reconciled_info()
for move in self:
if move.invoice_payments_widget:
inv_number = move.name
flag = False
payment_lines = set()
for line in self.line_ids:
for line in move.line_ids:
payment_lines.update(
line.mapped("matched_credit_ids.credit_move_id.id")
)
payment_lines.update(
line.mapped("matched_debit_ids.debit_move_id.id")
)
payment_move_line_ids = (
self.env["account.move.line"]
.browse(list(payment_lines))
.sorted()
)
payment_move_line_ids = (
self.env["account.move.line"].browse(list(payment_lines)).sorted()
)

for mvl in payment_move_line_ids:
# get bank payment line
if mvl.move_id and mvl.id == item["payment_id"]:
for pay_li in mvl.bank_payment_line_id.payment_line_ids:
# Get related payment line ref
if pay_li.communication == inv_number:
item["amount"] = pay_li.amount_currency
# for non-ach payment
# Deduct the discount only for the related payment.
# Discount is applied on the last payment (i.e. fully reconciled).
if (
not mvl.bank_payment_line_id
and mvl.move_id.id == self.id
and item["account_payment_id"] == mvl.payment_id.id
):
if mvl.full_reconcile_id and not flag:
item["amount"] = item["amount"] - self.discount_taken
flag = True

for item in move.invoice_payments_widget["content"]:
# get payment line
if mvl.payment_id.id == item["account_payment_id"]:
for pay_li in mvl.payment_id.line_ids.filtered(
lambda line: not line.reconciled
):
# Get related payment line ref
if inv_number in pay_li.name:
item["amount"] = abs(pay_li.amount_currency)
# for non-ach payment
# Deduct the discount only for the related payment.
# Discount is applied on the last payment (i.e. fully reconciled).
if (
mvl.payment_id
and mvl.move_id.id == self.id
and item["account_payment_id"] == mvl.payment_id.id
):
if mvl.full_reconcile_id and not flag:
item["amount"] = item["amount"] - move.discount_taken
flag = True
return res

def _prepare_discount_move_line(self, vals):
valid = False
for invoice in self:
if (
invoice.invoice_payment_term_id
and invoice.invoice_payment_term_id.is_discount
and invoice.invoice_payment_term_id.line_ids
):
discount_information = (
invoice.invoice_payment_term_id._check_payment_term_discount(
invoice, invoice.date_invoice
)
)
discount_amt = discount_information[0]
discount_account_id = discount_information[1]
if discount_amt > 0.0:
vals.update(
{
"account_id": discount_account_id,
"move_id": invoice.id,
"bank_payment_line_id": False,
"name": "Early Pay Discount",
}
)
if invoice.type == "out_invoice":
vals.update({"credit": 0.0, "debit": discount_amt})
valid = True
elif invoice.type == "in_invoice":
vals.update({"credit": discount_amt, "debit": 0.0})
valid = True
if valid:
return vals
else:
return {}

def _prepare_writeoff_move_line(self, payment_line, vals):
for invoice in self:
note = ""
if payment_line.reason_code:
note = payment_line.reason_code.display_name + ": "
if payment_line.note:
note += payment_line.note
vals.update(
{
"account_id": payment_line.writeoff_account_id.id,
"bank_payment_line_id": False,
"name": note,
"move_id": invoice.id,
}
)
if invoice.move_type == "out_invoice":
vals.update({"credit": 0.0, "debit": payment_line.payment_difference})
elif invoice.move_type == "in_invoice":
vals.update({"credit": payment_line.payment_difference, "debit": 0.0})
return vals
6 changes: 3 additions & 3 deletions account_banking_ach_discount/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class AccountPaymentLine(models.Model):
domain=[("deprecated", "!=", True)],
copy=False,
)
reason_code = fields.Many2one("payment.adjustment.reason", string="Reason Code")
note = fields.Text("Note")
payment_difference = fields.Float(string="Payment Difference")
reason_code = fields.Many2one("payment.adjustment.reason")
note = fields.Text()
payment_difference = fields.Float()
move_id = fields.Many2one(
"account.move", related="move_line_id.move_id", store=True
)
Expand Down
26 changes: 26 additions & 0 deletions account_banking_ach_discount/models/account_payment_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


class AccountPaymentOrder(models.Model):
_inherit = "account.payment.line"

def _prepare_account_payment_vals(self):
values = super()._prepare_account_payment_vals()
note = ""
if self.reason_code:
note = self.reason_code.display_name + ": "
if self.note:
note += self.note
payment_difference = self.payment_difference
if self.payment_type == "outbound":
payment_difference *= -1
write_off_line_vals = {
"account_id": self.writeoff_account_id.id,
"name": note,
"amount_currency": payment_difference,
"balance": payment_difference,
}
values["write_off_line_vals"] = [write_off_line_vals]
return values
102 changes: 0 additions & 102 deletions account_banking_ach_discount/models/account_payment_order.py

This file was deleted.

26 changes: 0 additions & 26 deletions account_banking_ach_discount/models/bank_payment_line.py

This file was deleted.

3 changes: 3 additions & 0 deletions account_banking_ach_discount/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

* Bhavesh Odedra <[email protected]>
* Maxime Chambreuil <[email protected]>

* ForgeFlow <https://www.forgeflow.com>
* Jasmin Solanki <[email protected]>
25 changes: 0 additions & 25 deletions account_banking_ach_discount/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,4 @@
</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="arch" type="xml">
<field name="amount_currency" position="after">
<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="arch" type="xml">
<field name="amount_currency" position="after">
<field name="discount_amount" />
<field name="total_amount" />
</field>
</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ class AccountPaymentRegister(models.TransientModel):
_inherit = "account.payment.register"

def make_payments(self):
if self.payment_method_id and self.payment_method_id.code in (
if self.payment_method_code and self.payment_method_code in (
"ACH-In",
"ACH-Out",
):
action = False
payment_mode = self.env["account.payment.mode"].search(
[
("payment_type", "=", self.payment_type),
("payment_method_id", "=", self.payment_method_id.id),
(
"payment_method_id",
"=",
self.payment_method_line_id.payment_method_id.id,
),
("payment_order_ok", "=", True),
],
limit=1,
Expand Down

0 comments on commit ef21873

Please sign in to comment.