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

View File

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

View File

@@ -5,12 +5,14 @@ from odoo import models
class AccountMassReconcileMethod(models.Model): class AccountMassReconcileMethod(models.Model):
_inherit = 'account.mass.reconcile.method' _inherit = "account.mass.reconcile.method"
def _selection_name(self): def _selection_name(self):
methods = super()._selection_name() methods = super()._selection_name()
methods += [ 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 return methods

View File

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

View File

@@ -3,13 +3,23 @@
<record id="view_mass_reconcile_form" model="ir.ui.view"> <record id="view_mass_reconcile_form" model="ir.ui.view">
<field name="name">account.mass.reconcile.form</field> <field name="name">account.mass.reconcile.form</field>
<field name="model">account.mass.reconcile</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"> <field name="arch" type="xml">
<page name="information" position="inside"> <page name="information" position="inside">
<group colspan="2" col="2"> <group colspan="2" col="2">
<separator colspan="4" string="Advanced. Partner and Ref Deep Search"/> <separator
<label for="reconcile_method" string="Match multiple debit vs multiple credit entries. Allow partial reconciliation. colspan="4"
The lines should have the partner, the credit entry ref is searched inside the debit entry ref." 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> </group>
</page> </page>
</field> </field>