Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] account_payment_line #572

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:255742abf8b18f2210925ddcb12a12a065e1c601d70058f9f45d56df5ff0f6fb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/14.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-14-0/account-payment-14-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=14.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:%2014.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. <chris.ormaza@forgeflow.com>

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/14.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": "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 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

Check warning on line 17 in account_payment_line/hooks.py

View check run for this annotation

Codecov / codecov/patch

account_payment_line/hooks.py#L17

Added line #L17 was not covered by tests

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

if pay.move_id.statement_line_id:
continue

Check warning on line 22 in account_payment_line/hooks.py

View check run for this annotation

Codecov / codecov/patch

account_payment_line/hooks.py#L22

Added line #L22 was not covered by tests

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(

Check warning on line 30 in account_payment_line/hooks.py

View check run for this annotation

Codecov / codecov/patch

account_payment_line/hooks.py#L30

Added line #L30 was not covered by tests
_("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(

Check warning on line 45 in account_payment_line/hooks.py

View check run for this annotation

Codecov / codecov/patch

account_payment_line/hooks.py#L45

Added line #L45 was not covered by tests
_(
"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 AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

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
Loading