Skip to content

Commit

Permalink
[MIG] account_payment_netting : Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pani-k-folk committed Dec 4, 2024
1 parent 045cbdb commit 63c7595
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 30 deletions.
10 changes: 5 additions & 5 deletions account_payment_netting/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -60,7 +60,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/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-financial-tools/issues/new?body=module:%20account_payment_netting%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_payment_netting%0Aversion:%2015.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.

Expand Down Expand Up @@ -99,6 +99,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kittiu|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_payment_netting/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
59 changes: 51 additions & 8 deletions account_payment_netting/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
{
Expand All @@ -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
Expand All @@ -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,
)

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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

Expand All @@ -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)
2 changes: 1 addition & 1 deletion account_payment_netting/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* Kitti Upariphutthiphong <[email protected]>
* Saran Lim. <[email protected]>
* Saran Lim. <[email protected]>
18 changes: 10 additions & 8 deletions account_payment_netting/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Account Payment Netting</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8364edf09da1fd6decbf2c97a25bd9e54b3e4c605fd65666712c3cc646d2fc1e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_payment_netting"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_payment_netting"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_payment_netting"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_payment_netting"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allow net payment on AR/AP invoice from the same business partner.</p>
<p><strong>NOTE</strong>: This module is influenced by account_netting,
but make it more user friendly when netting invoices.
Expand Down Expand Up @@ -406,7 +406,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_payment_netting%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_payment_netting%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -427,13 +427,15 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/kittiu"><img alt="kittiu" src="https://github.com/kittiu.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/account_payment_netting">OCA/account-financial-tools</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_payment_netting">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions account_payment_netting/wizards/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions setup/account_payment_netting/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 63c7595

Please sign in to comment.