Skip to content

Commit

Permalink
[14.0][ADD] account_payment_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisOForgeFlow committed Aug 4, 2023
1 parent a0baa1a commit c487d9e
Show file tree
Hide file tree
Showing 31 changed files with 2,163 additions and 0 deletions.
Empty file added account_payment_line/README.rst
Empty file.
5 changes: 5 additions & 0 deletions account_payment_line/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2022 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import models
from .hooks import post_load_hook
21 changes: 21 additions & 0 deletions account_payment_line/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Payment Counterpart Lines",
"summary": """Payment Counterpart Lines""",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-payment",
"category": "Account",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"depends": ["account"],
"data": [
"security/ir.model.access.csv",
"views/account_payment_views.xml",
],
"maintainers": ["ChrisOForgeFlow"],
"installable": True,
"post_load": "post_load_hook",
"auto_install": False,
}
92 changes: 92 additions & 0 deletions account_payment_line/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2022 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _
from odoo.exceptions import UserError

from odoo.addons.account.models.account_payment import (
AccountPayment as AccountPaymentClass,
)


def post_load_hook(): # noqa: C901
def _synchronize_from_moves_new(self, changed_fields):
if not self.line_payment_counterpart_ids:
return self._synchronize_from_moves_original(changed_fields)
if self._context.get("skip_account_move_synchronization"):
return

for pay in self.with_context(skip_account_move_synchronization=True):

if pay.move_id.statement_line_id:
continue

move = pay.move_id
move_vals_to_write = {}
payment_vals_to_write = {}

if "journal_id" in changed_fields:
if pay.journal_id.type not in ("bank", "cash"):
raise UserError(
_("A payment must always belongs to a bank or cash journal.")
)

if "line_ids" in changed_fields:
all_lines = move.line_ids
(
liquidity_lines,
counterpart_lines,
writeoff_lines,
) = pay._seek_for_lines()

if any(
line.currency_id != all_lines[0].currency_id for line in all_lines
):
raise UserError(
_(
"Journal Entry %s is not valid. "
"In order to proceed, "
"the journal items must "
"share the same currency.",
move.display_name,
)
)

if "receivable" in counterpart_lines.mapped(
"account_id.user_type_id.type"
):
partner_type = "customer"
else:
partner_type = "supplier"

liquidity_amount = liquidity_lines.amount_currency

move_vals_to_write.update(
{
"currency_id": liquidity_lines.currency_id.id,
"partner_id": liquidity_lines.partner_id.id,
}
)
destination_account_id = counterpart_lines.mapped("account_id")[0].id
payment_vals_to_write.update(
{
"amount": abs(liquidity_amount),
"partner_type": partner_type,
"currency_id": liquidity_lines.currency_id.id,
"destination_account_id": destination_account_id,
"partner_id": liquidity_lines.partner_id.id,
}
)
if liquidity_amount > 0.0:
payment_vals_to_write.update({"payment_type": "inbound"})
elif liquidity_amount < 0.0:
payment_vals_to_write.update({"payment_type": "outbound"})

move.write(move._cleanup_write_orm_values(move, move_vals_to_write))
pay.write(move._cleanup_write_orm_values(pay, payment_vals_to_write))

if not hasattr(AccountPaymentClass, "_synchronize_from_moves_original"):
AccountPaymentClass._synchronize_from_moves_original = (
AccountPaymentClass._synchronize_from_moves
)
AccountPaymentClass._synchronize_from_moves = _synchronize_from_moves_new
3 changes: 3 additions & 0 deletions account_payment_line/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import counterpart_line
from . import account_payment
from . import account_move
12 changes: 12 additions & 0 deletions account_payment_line/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2022 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

payment_line_id = fields.Many2one(
"account.payment.counterpart.line", string="Payment line", ondelete="set null"
)
Loading

0 comments on commit c487d9e

Please sign in to comment.