Skip to content

Commit

Permalink
[ADD] account_payment_order_by_partner: add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Jan 20, 2025
1 parent 39e35b1 commit 71e8a22
Show file tree
Hide file tree
Showing 18 changed files with 737 additions and 0 deletions.
90 changes: 90 additions & 0 deletions account_payment_order_by_partner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
================================
Account Payment Order By Partner
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8cec7dad270597148de4197592a735f1daf8daa01c6ed5381e1f2ce4b855e9a3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fbank--payment-lightgray.png?logo=github
:target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_by_partner
:alt: OCA/bank-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_order_by_partner
: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/bank-payment&target_branch=14.0
:alt: Try me on Runboat

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

This module enhances payment order functionality in Odoo by ensuring that all payment lines within a payment order belong to the same partner. This enforces stricter partner consistency and aligns with workflows that require one payment order per partner, improving data integrity and preventing inconsistent payments.

**Table of contents**

.. contents::
:local:

Usage
=====

This module introduces an option to restrict Payment Orders to a single partner.
To enable this feature:

1. Go to **Invoicing > Configuration > Payment Modes**.
2. In the desired Payment Mode, activate the checkbox **Individual Payment**.

When this option is enabled, all move lines in a Payment Order must belong to the same partner. Any attempt to add lines from a different partner will result in a validation error.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-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/bank-payment/issues/new?body=module:%20account_payment_order_by_partner%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
~~~~~~~

* Escodoo

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

* `Escodoo <https://escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[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.

This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_by_partner>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_payment_order_by_partner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions account_payment_order_by_partner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2025 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Payment Order By Partner",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/bank-payment",
"depends": [
"account_payment_order",
],
"data": [
"views/account_payment_mode.xml",
],
}
4 changes: 4 additions & 0 deletions account_payment_order_by_partner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_move
from . import account_payment_line
from . import account_payment_mode
from . import account_payment_order
15 changes: 15 additions & 0 deletions account_payment_order_by_partner/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMove(models.Model):

_inherit = "account.move"

def get_account_payment_domain(self, payment_mode):
domain = super().get_account_payment_domain(payment_mode)
if payment_mode.individual_payment:
domain.append(("payment_line_ids.partner_id", "=", self.partner_id.id))
return domain

Check warning on line 15 in account_payment_order_by_partner/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_payment_order_by_partner/models/account_move.py#L14-L15

Added lines #L14 - L15 were not covered by tests
24 changes: 24 additions & 0 deletions account_payment_order_by_partner/models/account_payment_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import ValidationError


class AccountPaymentLine(models.Model):

_inherit = "account.payment.line"

@api.constrains("partner_id", "order_id")
def _check_partner_consistency(self):
for line in self:
if line.order_id.payment_mode_id.individual_payment:
partners = line.order_id.payment_line_ids.mapped("partner_id")
if len(set(partners)) > 1:
raise ValidationError(
_(
"The payment order contains lines with multiple partners. "
"When the payment mode requires individual payments, "
"all lines must belong to the same partner."
)
)
14 changes: 14 additions & 0 deletions account_payment_order_by_partner/models/account_payment_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2025 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountPaymentMode(models.Model):

_inherit = "account.payment.mode"
individual_payment = fields.Boolean(
string="Individual Payment per Partner",
help="Enable this option to process payments individually"
" for this partner instead of combining them in a single payment order.",
)
24 changes: 24 additions & 0 deletions account_payment_order_by_partner/models/account_payment_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo.exceptions import UserError


class AccountPaymentOrder(models.Model):

_inherit = "account.payment.order"

def draft2open(self):
for order in self:
if order.payment_mode_id.individual_payment:
partners = order.payment_line_ids.mapped("partner_id")
if len(set(partners.ids)) > 1:
raise UserError(

Check warning on line 17 in account_payment_order_by_partner/models/account_payment_order.py

View check run for this annotation

Codecov / codecov/patch

account_payment_order_by_partner/models/account_payment_order.py#L17

Added line #L17 was not covered by tests
_(
"The Payment Mode '%s' requires individual payments. "
"Ensure that all payment lines belong to the same partner."
)
% order.payment_mode_id.name
)
super().draft2open()
4 changes: 4 additions & 0 deletions account_payment_order_by_partner/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[email protected]>
1 change: 1 addition & 0 deletions account_payment_order_by_partner/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module enhances payment order functionality in Odoo by ensuring that all payment lines within a payment order belong to the same partner. This enforces stricter partner consistency and aligns with workflows that require one payment order per partner, improving data integrity and preventing inconsistent payments.
7 changes: 7 additions & 0 deletions account_payment_order_by_partner/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module introduces an option to restrict Payment Orders to a single partner.
To enable this feature:

1. Go to **Invoicing > Configuration > Payment Modes**.
2. In the desired Payment Mode, activate the checkbox **Individual Payment**.

When this option is enabled, all move lines in a Payment Order must belong to the same partner. Any attempt to add lines from a different partner will result in a validation error.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 71e8a22

Please sign in to comment.