-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0baa1a
commit c487d9e
Showing
31 changed files
with
2,163 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
Oops, something went wrong.