From 4e66e28d8921a5a10753366466a24f44955ff3f0 Mon Sep 17 00:00:00 2001 From: Damien Crier Date: Sun, 26 Jul 2020 09:20:17 +0200 Subject: [PATCH] [IMP] account_mass_reconcile_ref_deep_search: black, isort, prettier --- .../__manifest__.py | 20 ++- .../models/advanced_reconciliation.py | 29 ++-- .../models/mass_reconcile.py | 8 +- .../test_account_reconcile_ref_deep_search.py | 132 +++++++++++------- .../views/mass_reconcile_view.xml | 22 ++- 5 files changed, 127 insertions(+), 84 deletions(-) diff --git a/account_mass_reconcile_ref_deep_search/__manifest__.py b/account_mass_reconcile_ref_deep_search/__manifest__.py index 0b57a2cb..17eb3a14 100644 --- a/account_mass_reconcile_ref_deep_search/__manifest__.py +++ b/account_mass_reconcile_ref_deep_search/__manifest__.py @@ -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, } diff --git a/account_mass_reconcile_ref_deep_search/models/advanced_reconciliation.py b/account_mass_reconcile_ref_deep_search/models/advanced_reconciliation.py index 8555391a..6eb2f985 100644 --- a/account_mass_reconcile_ref_deep_search/models/advanced_reconciliation.py +++ b/account_mass_reconcile_ref_deep_search/models/advanced_reconciliation.py @@ -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 + ) diff --git a/account_mass_reconcile_ref_deep_search/models/mass_reconcile.py b/account_mass_reconcile_ref_deep_search/models/mass_reconcile.py index af717b58..bded855f 100644 --- a/account_mass_reconcile_ref_deep_search/models/mass_reconcile.py +++ b/account_mass_reconcile_ref_deep_search/models/mass_reconcile.py @@ -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 diff --git a/account_mass_reconcile_ref_deep_search/tests/test_account_reconcile_ref_deep_search.py b/account_mass_reconcile_ref_deep_search/tests/test_account_reconcile_ref_deep_search.py index 5c8cb631..992f78aa 100644 --- a/account_mass_reconcile_ref_deep_search/tests/test_account_reconcile_ref_deep_search.py +++ b/account_mass_reconcile_ref_deep_search/tests/test_account_reconcile_ref_deep_search.py @@ -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) diff --git a/account_mass_reconcile_ref_deep_search/views/mass_reconcile_view.xml b/account_mass_reconcile_ref_deep_search/views/mass_reconcile_view.xml index f40d1c03..325be42c 100644 --- a/account_mass_reconcile_ref_deep_search/views/mass_reconcile_view.xml +++ b/account_mass_reconcile_ref_deep_search/views/mass_reconcile_view.xml @@ -1,16 +1,26 @@ - + account.mass.reconcile.form account.mass.reconcile - + - - + +