Skip to content

Commit

Permalink
[MIG] account_reconcile_restrict_partner_mismatch: Migration to 18.0
Browse files Browse the repository at this point in the history
[Fix] fix adapt ui for odoo18

[Fix] Fix res_config_view for odoo18

[Fix] fix review point
  • Loading branch information
Lukas Tran committed Dec 18, 2024
1 parent 6a2b8f6 commit 4ee453e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 31 deletions.
1 change: 1 addition & 0 deletions account_reconcile_restrict_partner_mismatch/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Other credits
-------------

The migration of this module from 13.0 to 14.0 was financially supported
The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp

Maintainers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

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


Expand All @@ -21,18 +20,18 @@ def _check_partner_mismatch_on_reconcile(self):
in ("asset_receivable", "liability_payable")
)

def reconcile(self):
def _reconcile_plan(self, reconciliation_plan):
# to be consistent with parent method
if self:
if reconciliation_plan:
partners = set()
for line in self:
if line._check_partner_mismatch_on_reconcile:
partners.add(line.partner_id.id)
for lines in reconciliation_plan:
checked_lines = lines.filtered(lambda l: l._check_partner_mismatch_on_reconcile)
partners.update(line.partner_id.id for line in checked_lines)
if len(partners) > 1:
raise UserError(
_(
self.env._(
"The partner has to be the same on all"
" lines for receivable and payable accounts!"
)
)
return super().reconcile()
return super()._reconcile_plan(reconciliation_plan)
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
The migration of this module from 13.0 to 14.0 was financially supported
The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<field name="name">Reconciled items with partner mismatch</field>
<field name="model">account.reconcile.partner.mismatch.report</field>
<field name="arch" type="xml">
<tree create="false" delete="false" edit="false">
<list create="false" delete="false" edit="false">
<!-- links are not clickable in tree view
only after open form view -->
<field name="partial_reconcile_id" />
Expand All @@ -17,7 +17,7 @@
<field name="credit_partner_id" />
<field name="account_type" />
<field name="account_id" />
</tree>
</list>
</field>
</record>
<record id="account_reconcile_partner_mismatch_report_view_form" model="ir.ui.view">
Expand Down Expand Up @@ -57,7 +57,7 @@
>
<field name="name">Reconciled items with partner mismatch</field>
<field name="res_model">account.reconcile.partner.mismatch.report</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>
<menuitem
id="menu_account_reconcile_partner_mismatch_report"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p>The migration of this module from 13.0 to 14.0 was financially supported
The migration of this module from 16.0 to 18.0 was financially supported
by Camptocamp</p>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import UserError
from odoo.tests import tagged

from odoo.addons.base.tests.common import BaseCommon


@tagged("-at_install", "post_install")
class TestReconciliation(BaseCommon):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -141,3 +143,28 @@ def test_reconcile_accounts_excluded(self):
self.aml.move_id.action_post()
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped("reconciled")))

def test_reconcile_same_partner(self):
"""Test reconciliation of two move lines with same partner works."""
self.aml.move_id.company_id.restrict_partner_mismatch_on_reconcile = True
# Set same partner for both lines
self.aml.write({'partner_id': self.partner.id})
self.aml.move_id.action_post()
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped("reconciled")))

def test_reconcile_different_journals(self):
"""Test reconciliation works across different journals."""
# Create second journal
cash_journal = self.env["account.journal"].create(
{"name": "Cash", "type": "cash", "code": "CSH67"}
)

# Update journals of existing moves
self.aml[0].move_id.journal_id = self.bank_journal
self.aml[1].move_id.journal_id = cash_journal

# Test reconciliation
self.aml.move_id.action_post()
self.aml.reconcile()
self.assertTrue(all(self.aml.mapped("reconciled")))
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='sale_activity_type_id']/parent::group"
expr="//field[@name='invoice_reference_type']/parent::group"
position="after"
>
<group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="quick_edit_mode" position="after">
<h2>Partners Mismatch Restriction on Reconcile</h2>
<div class="row mt16 o_settings_container" id="quick_edit_mode">
<div class="col-12 col-lg-12 o_setting_box">
<div class="o_setting_left_pane mt16">
<div>
<field name="restrict_partner_mismatch_on_reconcile" />
</div>
</div>
<div class="o_setting_right_pane mt16">
<label for="restrict_partner_mismatch_on_reconcile" />
<div class="text-muted">
Check this if you want to avoid partner mismatch (several different partners) on reconciliation.
</div>
</div>
</div>
</div>
</div>
<block id="quick_edit_mode" position="after">
<block
title="Partners Mismatch Restriction on Reconcile"
name="account_reconcile_restrict_partner_mismatch"
>
<setting
id="restrict_partner_mismatch_on_reconcile"
help="Check this if you want to avoid partner mismatch (several different partners) on reconciliation."
>
<field name="restrict_partner_mismatch_on_reconcile" />
</setting>
</block>
</block>
</field>
</record>
</odoo>

0 comments on commit 4ee453e

Please sign in to comment.