From 63c759537cd7837386c200147e3fcc4254bee402 Mon Sep 17 00:00:00 2001 From: Pani-k-folk Date: Wed, 4 Dec 2024 10:41:27 +0700 Subject: [PATCH] [MIG] account_payment_netting : Migration to 15.0 --- account_payment_netting/README.rst | 10 ++-- account_payment_netting/__manifest__.py | 2 +- .../models/account_payment.py | 59 ++++++++++++++++--- .../readme/CONTRIBUTORS.rst | 2 +- .../static/description/index.html | 18 +++--- .../tests/test_account_payment_netting.py | 2 +- .../wizards/account_payment_register.py | 12 ++-- .../odoo/addons/account_payment_netting | 1 + setup/account_payment_netting/setup.py | 6 ++ 9 files changed, 82 insertions(+), 30 deletions(-) create mode 120000 setup/account_payment_netting/odoo/addons/account_payment_netting create mode 100644 setup/account_payment_netting/setup.py diff --git a/account_payment_netting/README.rst b/account_payment_netting/README.rst index 3e7f0a3f7a2..0ffad7b9f17 100644 --- a/account_payment_netting/README.rst +++ b/account_payment_netting/README.rst @@ -17,13 +17,13 @@ Account Payment Netting :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--financial--tools-lightgray.png?logo=github - :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_payment_netting + :target: https://github.com/OCA/account-financial-tools/tree/15.0/account_payment_netting :alt: OCA/account-financial-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_payment_netting + :target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_payment_netting :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-financial-tools&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=15.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -60,7 +60,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -99,6 +99,6 @@ Current `maintainer `__: |maintainer-kittiu| -This module is part of the `OCA/account-financial-tools `_ project on GitHub. +This module is part of the `OCA/account-financial-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_netting/__manifest__.py b/account_payment_netting/__manifest__.py index eca1f90cce1..483a257179b 100644 --- a/account_payment_netting/__manifest__.py +++ b/account_payment_netting/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Account Payment Netting", - "version": "16.0.1.0.0", + "version": "15.0.1.0.0", "summary": "Net Payment on AR/AP invoice from the same partner", "category": "Accounting & Finance", "author": "Ecosoft, Odoo Community Association (OCA)", diff --git a/account_payment_netting/models/account_payment.py b/account_payment_netting/models/account_payment.py index e3ddc435b36..449e0f421ed 100644 --- a/account_payment_netting/models/account_payment.py +++ b/account_payment_netting/models/account_payment.py @@ -18,7 +18,7 @@ def _synchronize_from_moves(self, changed_fields): return super()._synchronize_from_moves(changed_fields) def _get_move_line_vals_netting( - self, name, date, remaining_amount_currency, currency, account + self, name, date, remaining_amount_currency, currency, account, debit, credit ): return [ { @@ -28,15 +28,18 @@ def _get_move_line_vals_netting( "currency_id": currency.id, "partner_id": self.partner_id.id, "account_id": account.id, + "debit": debit, + "credit": credit, } ] + # user_type_id.type def _prepare_move_line_default_vals(self, write_off_line_vals=None): self.ensure_one() if self.env.context.get("netting"): domain = [ ("move_id", "in", self.env.context.get("active_ids", [])), - ("account_type", "in", ["asset_receivable", "liability_payable"]), + ("account_internal_type", "in", ["receivable", "payable"]), ("reconciled", "=", False), ] # Sort by amount @@ -45,12 +48,13 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): ml_reconciled = self.env["account.move.line"].search(domain) if self.payment_type == "inbound": move_lines = sorted( - ml_reconciled, key=lambda k: (k.move_type, k.amount_residual) + ml_reconciled, + key=lambda k: (k.move_id.move_type, k.amount_residual), ) else: move_lines = sorted( ml_reconciled, - key=lambda k: (k.move_type, -abs(k.amount_residual)), + key=lambda k: (k.move_id.move_type, -abs(k.amount_residual)), reverse=True, ) @@ -67,7 +71,7 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): sign = ( 1 if self.payment_type == "outbound" - and line.move_type == "in_invoice" + and line.move_id.move_type == "in_invoice" else -1 ) amount_residual_currency = line.amount_residual_currency @@ -93,10 +97,16 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): sign * amount_total_currency, line.currency_id, line.account_id, + abs(amount_total_currency) + if line.account_internal_type == "payable" + else 0, + abs(amount_total_currency) + if line.account_internal_type == "receivable" + else 0, ) break # Check if move_type is changed - if current_move_type and current_move_type != line.move_type: + if current_move_type and current_move_type != line.move_id.move_type: # Get min amount from remaining_amount_currency and amount_residual_currency if not write_off_line_vals: amount_remaining = min( @@ -117,19 +127,31 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): sign * amount_remaining, line.currency_id, line.account_id, + abs(amount_remaining) + if line.account_internal_type == "payable" + else 0, + abs(amount_remaining) + if line.account_internal_type == "receivable" + else 0, ) remaining_amount_currency = abs(remaining_amount_currency) - abs( amount_remaining ) # First line or same move_type else: - current_move_type = line.move_type + current_move_type = line.move_id.move_type line_vals_list += self._get_move_line_vals_netting( line.move_id.name, self.date, -1 * amount_residual_currency, line.currency_id, line.account_id, + abs(amount_residual_currency) + if line.account_internal_type == "payable" + else 0, + abs(amount_residual_currency) + if line.account_internal_type == "receivable" + else 0, ) remaining_amount_currency += amount_residual_currency @@ -143,6 +165,27 @@ def _prepare_move_line_default_vals(self, write_off_line_vals=None): else -liquidity_amount_currency, self.currency_id, self.outstanding_account_id, + liquidity_amount_currency if self.payment_type == "inbound" else 0, + liquidity_amount_currency if self.payment_type == "outbound" else 0, + ) + if write_off_line_vals: + account_id = self.env["account.account"].browse( + write_off_line_vals["account_id"] + ) + line_vals_list += self._get_move_line_vals_netting( + write_off_line_vals["name"], + self.date, + write_off_line_vals["amount"] + if self.payment_type == "inbound" + else -1 * write_off_line_vals["amount"], + self.currency_id, + account_id, + write_off_line_vals["amount"] + if self.payment_type == "inbound" + else 0, + write_off_line_vals["amount"] + if self.payment_type == "outbound" + else 0, ) - return line_vals_list + write_off_line_vals + return line_vals_list return super()._prepare_move_line_default_vals(write_off_line_vals) diff --git a/account_payment_netting/readme/CONTRIBUTORS.rst b/account_payment_netting/readme/CONTRIBUTORS.rst index da3b6a139c2..9cf8003996d 100644 --- a/account_payment_netting/readme/CONTRIBUTORS.rst +++ b/account_payment_netting/readme/CONTRIBUTORS.rst @@ -1,2 +1,2 @@ * Kitti Upariphutthiphong -* Saran Lim. \ No newline at end of file +* Saran Lim. diff --git a/account_payment_netting/static/description/index.html b/account_payment_netting/static/description/index.html index 68b8980f5df..57a6b3b43a1 100644 --- a/account_payment_netting/static/description/index.html +++ b/account_payment_netting/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -369,7 +369,7 @@

Account Payment Netting

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:8364edf09da1fd6decbf2c97a25bd9e54b3e4c605fd65666712c3cc646d2fc1e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

This module allow net payment on AR/AP invoice from the same business partner.

NOTE: This module is influenced by account_netting, but make it more user friendly when netting invoices. @@ -406,7 +406,7 @@

Bug Tracker

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -427,13 +427,15 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

Current maintainer:

kittiu

-

This module is part of the OCA/account-financial-tools project on GitHub.

+

This module is part of the OCA/account-financial-tools project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/account_payment_netting/tests/test_account_payment_netting.py b/account_payment_netting/tests/test_account_payment_netting.py index 220b2513c17..0e50124ed68 100644 --- a/account_payment_netting/tests/test_account_payment_netting.py +++ b/account_payment_netting/tests/test_account_payment_netting.py @@ -27,7 +27,7 @@ def setUpClass(cls): ) cls.account_expense = cls.env["account.account"].search( [ - ("account_type", "=", "expense"), + ("internal_group", "=", "expense"), ("company_id", "=", cls.env.company.id), ], limit=1, diff --git a/account_payment_netting/wizards/account_payment_register.py b/account_payment_netting/wizards/account_payment_register.py index 892abebf7e0..77f0e4a3600 100644 --- a/account_payment_netting/wizards/account_payment_register.py +++ b/account_payment_netting/wizards/account_payment_register.py @@ -66,7 +66,7 @@ def default_get(self, fields_list): _("You can only register payment for posted journal entries.") ) - if line.account_type not in ("asset_receivable", "liability_payable"): + if line.account_internal_type not in ("receivable", "payable"): continue if line.currency_id: if line.currency_id.is_zero(line.amount_residual_currency): @@ -113,8 +113,8 @@ def _get_batch_communication(self, batch_result): return ", ".join(sorted(labels)) return super()._get_batch_communication(batch_result) - def _create_payment_vals_from_wizard(self, batch_result): - payment_vals = super()._create_payment_vals_from_wizard(batch_result) + def _create_payment_vals_from_wizard(self): + payment_vals = super()._create_payment_vals_from_wizard() payment_vals["netting"] = self.netting return payment_vals @@ -126,9 +126,9 @@ def _compute_from_lines(self): continue batches = wizard._get_batches() - balance = sum([sum(batch["lines"].mapped("balance")) for batch in batches]) + balance = sum(sum(batch["lines"].mapped("balance")) for batch in batches) amount_currency = sum( - [sum(batch["lines"].mapped("amount_currency")) for batch in batches] + sum(batch["lines"].mapped("amount_currency")) for batch in batches ) if balance < 0.0: payment_type = "outbound" @@ -181,7 +181,7 @@ def _netting_reconcile_payment(self, to_process): moveline_obj = self.env["account.move.line"] domain = [ ("parent_state", "=", "posted"), - ("account_type", "in", ("asset_receivable", "liability_payable")), + ("account_internal_type", "in", ("receivable", "payable")), ("reconciled", "=", False), ] moves = self.env["account.move"].browse(self.env.context.get("active_ids")) diff --git a/setup/account_payment_netting/odoo/addons/account_payment_netting b/setup/account_payment_netting/odoo/addons/account_payment_netting new file mode 120000 index 00000000000..2777f222163 --- /dev/null +++ b/setup/account_payment_netting/odoo/addons/account_payment_netting @@ -0,0 +1 @@ +../../../../account_payment_netting \ No newline at end of file diff --git a/setup/account_payment_netting/setup.py b/setup/account_payment_netting/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_payment_netting/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)