[IMP] account_mass_reconcile_ref_deep_search: black, isort, prettier

This commit is contained in:
Damien Crier
2020-07-26 09:20:17 +02:00
committed by Diep Huu Hoang
parent c212cd0ad1
commit 4e66e28d89
5 changed files with 127 additions and 84 deletions

View File

@@ -1,15 +1,13 @@
# Copyright 2015-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
{
'name': 'Mass Reconcile Ref Deep Search',
'version': '12.0.1.0.0',
'author': "Camptocamp, Odoo Community Association (OCA)",
'category': 'Finance',
'website': 'https://github.com/account-reconcile',
'license': 'AGPL-3',
'depends': ['account_mass_reconcile'],
'data': [
'views/mass_reconcile_view.xml'
],
'installable': True,
"name": "Mass Reconcile Ref Deep Search",
"version": "13.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"category": "Finance",
"website": "https://github.com/account-reconcile",
"license": "AGPL-3",
"depends": ["account_mass_reconcile"],
"data": ["views/mass_reconcile_view.xml"],
"installable": True,
}

View File

@@ -1,13 +1,14 @@
# Copyright 2015-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import _, models
from itertools import product
from odoo import _, models
class MassReconciledAdvancedRefDeepSearch(models.TransientModel):
_name = 'mass.reconcile.advanced.ref.deep.search'
_inherit = 'mass.reconcile.advanced.ref'
_name = "mass.reconcile.advanced.ref.deep.search"
_inherit = "mass.reconcile.advanced.ref"
@staticmethod
def _compare_values(key, value, opposite_value):
@@ -21,8 +22,7 @@ class MassReconciledAdvancedRefDeepSearch(models.TransientModel):
if not (value and opposite_value):
return False
if value == opposite_value or \
(key == 'ref' and value in opposite_value):
if value == opposite_value or (key == "ref" and value in opposite_value):
return True
return False
@@ -34,8 +34,7 @@ class MassReconciledAdvancedRefDeepSearch(models.TransientModel):
for value, ovalue in product(values, opposite_values):
# we do not need to compare all values, if one matches
# we are done
if MassReconciledAdvancedRefDeepSearch._compare_values(
key, value, ovalue):
if MassReconciledAdvancedRefDeepSearch._compare_values(key, value, ovalue):
return True
return False
@@ -46,12 +45,14 @@ class MassReconciledAdvancedRefDeepSearch(models.TransientModel):
"""
mkey, mvalue = matcher
omkey, omvalue = opposite_matcher
assert mkey == omkey, \
(_("A matcher %s is compared with a matcher %s, the _matchers and "
"_opposite_matchers are probably wrong") % (mkey, omkey))
assert mkey == omkey, _(
"A matcher %s is compared with a matcher %s, the _matchers and "
"_opposite_matchers are probably wrong"
) % (mkey, omkey)
if not isinstance(mvalue, (list, tuple)):
mvalue = mvalue,
mvalue = (mvalue,)
if not isinstance(omvalue, (list, tuple)):
omvalue = omvalue,
return MassReconciledAdvancedRefDeepSearch.\
_compare_matcher_values(mkey, mvalue, omvalue)
omvalue = (omvalue,)
return MassReconciledAdvancedRefDeepSearch._compare_matcher_values(
mkey, mvalue, omvalue
)

View File

@@ -5,12 +5,14 @@ from odoo import models
class AccountMassReconcileMethod(models.Model):
_inherit = 'account.mass.reconcile.method'
_inherit = "account.mass.reconcile.method"
def _selection_name(self):
methods = super()._selection_name()
methods += [
('mass.reconcile.advanced.ref.deep.search',
'Advanced. Partner and Ref. Deep Search'),
(
"mass.reconcile.advanced.ref.deep.search",
"Advanced. Partner and Ref. Deep Search",
),
]
return methods

View File

@@ -4,68 +4,100 @@ from odoo.tests import SavepointCase
class TestAccountReconcileRefDeepSearch(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env.ref('base.res_partner_18')
cls.account_receivable = cls.env['account.account'].search([
('user_type_id', '=',
cls.env.ref('account.data_account_type_receivable').id)
], limit=1)
account_revenue = cls.env['account.account'].search([
('user_type_id', '=',
cls.env.ref('account.data_account_type_revenue').id)
], limit=1)
sales_journal = cls.env['account.journal'].search([
('type', '=', 'sale')], limit=1)
cls.partner = cls.env.ref("base.res_partner_18")
cls.account_receivable = cls.env["account.account"].search(
[
(
"user_type_id",
"=",
cls.env.ref("account.data_account_type_receivable").id,
)
],
limit=1,
)
account_revenue = cls.env["account.account"].search(
[
(
"user_type_id",
"=",
cls.env.ref("account.data_account_type_revenue").id,
)
],
limit=1,
)
sales_journal = cls.env["account.journal"].search(
[("type", "=", "sale")], limit=1
)
# Create invoice
cls.cust_invoice = cls.env['account.invoice'].create({
'partner_id': cls.partner.id,
'type': 'out_invoice',
'account_id': cls.account_receivable.id,
'journal_id': sales_journal.id,
'invoice_line_ids': [(0, 0, {
'name': '[CONS_DEL01] Server',
'product_id': cls.env.ref('product.consu_delivery_01').id,
'account_id': account_revenue.id,
'price_unit': 1000.0,
'quantity': 1.0,
})],
'name': 'test_deep_search'
})
cls.cust_invoice = cls.env["account.invoice"].create(
{
"partner_id": cls.partner.id,
"type": "out_invoice",
"account_id": cls.account_receivable.id,
"journal_id": sales_journal.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "[CONS_DEL01] Server",
"product_id": cls.env.ref("product.consu_delivery_01").id,
"account_id": account_revenue.id,
"price_unit": 1000.0,
"quantity": 1.0,
},
)
],
"name": "test_deep_search",
}
)
cls.cust_invoice.action_invoice_open()
def test_account_reconcile_ref_deep_search(self):
self.assertEqual(self.cust_invoice.state, 'open')
bank_journal = self.env['account.journal'].search([
('type', '=', 'bank')], limit=1)
self.assertEqual(self.cust_invoice.state, "open")
bank_journal = self.env["account.journal"].search(
[("type", "=", "bank")], limit=1
)
# Create payment
payment = self.env['account.payment'].create({
'payment_type': 'inbound',
'partner_type': 'customer',
'partner_id': self.partner.id,
'journal_id': bank_journal.id,
'amount': 1000.0,
'communication': 'test_deep_search',
'payment_method_id': self.env['account.payment.method'].search([
('name', '=', 'Manual')], limit=1).id,
})
self.assertEqual(payment.state, 'draft')
payment = self.env["account.payment"].create(
{
"payment_type": "inbound",
"partner_type": "customer",
"partner_id": self.partner.id,
"journal_id": bank_journal.id,
"amount": 1000.0,
"communication": "test_deep_search",
"payment_method_id": self.env["account.payment.method"]
.search([("name", "=", "Manual")], limit=1)
.id,
}
)
self.assertEqual(payment.state, "draft")
payment.post()
self.assertEqual(payment.state, 'posted')
self.assertEqual(payment.state, "posted")
reconcile = self.env['account.mass.reconcile'].create({
'name': 'Test reconcile ref deep search',
'account': self.account_receivable.id,
'reconcile_method': [(0, 0, {
'name': 'mass.reconcile.advanced.ref.deep.search',
'date_base_on': 'newest',
})]
})
reconcile = self.env["account.mass.reconcile"].create(
{
"name": "Test reconcile ref deep search",
"account": self.account_receivable.id,
"reconcile_method": [
(
0,
0,
{
"name": "mass.reconcile.advanced.ref.deep.search",
"date_base_on": "newest",
},
)
],
}
)
count = reconcile.unreconciled_count
reconcile.run_reconcile()
self.assertEqual(self.cust_invoice.state, 'paid')
self.assertEqual(self.cust_invoice.state, "paid")
self.assertEqual(reconcile.unreconciled_count, count - 2)

View File

@@ -1,16 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_mass_reconcile_form" model="ir.ui.view">
<field name="name">account.mass.reconcile.form</field>
<field name="model">account.mass.reconcile</field>
<field name="inherit_id" ref="account_mass_reconcile.account_mass_reconcile_form"/>
<field
name="inherit_id"
ref="account_mass_reconcile.account_mass_reconcile_form"
/>
<field name="arch" type="xml">
<page name="information" position="inside">
<group colspan="2" col="2">
<separator colspan="4" string="Advanced. Partner and Ref Deep Search"/>
<label for="reconcile_method" string="Match multiple debit vs multiple credit entries. Allow partial reconciliation.
The lines should have the partner, the credit entry ref is searched inside the debit entry ref." colspan="4"/>
</group>
<separator
colspan="4"
string="Advanced. Partner and Ref Deep Search"
/>
<label
for="reconcile_method"
string="Match multiple debit vs multiple credit entries. Allow partial reconciliation.
The lines should have the partner, the credit entry ref is searched inside the debit entry ref."
colspan="4"
/>
</group>
</page>
</field>
</record>