Skip to content

Commit

Permalink
Merge PR #666 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by JordiBForgeFlow
  • Loading branch information
OCA-git-bot committed Jun 17, 2024
2 parents c4d9571 + cc35b89 commit f43b298
Show file tree
Hide file tree
Showing 20 changed files with 2,603 additions and 0 deletions.
98 changes: 98 additions & 0 deletions account_payment_line/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
=========================
Payment Counterpart Lines
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c26d5a975a2bc0e40ff5a615d5662ecbc7c7b40aa895c452573c3b18fc0b4b68
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github
:target: https://github.com/OCA/account-payment/tree/16.0/account_payment_line
:alt: OCA/account-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-payment-16-0/account-payment-16-0-account_payment_line
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-payment&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module is an utility module to add lines in payment, allowing users make
more complicated cases when processing payments, split on many invoices,
set up specific write-off and adding some analytic information

Add tool to proposal of payment distributions, ordering by due date

**Table of contents**

.. contents::
:local:

Usage
=====

You can use payment distribution suggestion, and if system found moves
pending to reconcile related with partner selected, system will create
all lines trying to pay all invoices until amount remain

You can add manually lines, if payment don't detect lines specified, payment
works as a normal payment

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-payment/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-payment/issues/new?body=module:%20account_payment_line%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ForgeFlow S.L.

Contributors
~~~~~~~~~~~~

* Christopher Ormaza. <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px
:target: https://github.com/ChrisOForgeFlow
:alt: ChrisOForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ChrisOForgeFlow|

This module is part of the `OCA/account-payment <https://github.com/OCA/account-payment/tree/16.0/account_payment_line>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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 AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

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 AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"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": "16.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 AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

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 "asset_receivable" in counterpart_lines.mapped(
"account_id.account_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
Loading

0 comments on commit f43b298

Please sign in to comment.