diff --git a/account_move_so_import/__manifest__.py b/account_move_so_import/__manifest__.py index 4c497083..d1bfd5b4 100644 --- a/account_move_so_import/__manifest__.py +++ b/account_move_so_import/__manifest__.py @@ -1,18 +1,18 @@ # Copyright 2011-2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) { - 'name': "Journal Entry Sale Order completion", - 'version': '12.0.1.0.0', - 'author': "Camptocamp,Odoo Community Association (OCA)", - 'maintainer': 'Camptocamp', - 'category': 'Finance', - 'complexity': 'easy', - 'depends': ['account_move_base_import', 'sale'], - 'website': 'http://www.camptocamp.com', - 'data': [ - 'data/completion_rule_data.xml', + "name": "Journal Entry Sale Order completion", + "version": "12.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "maintainer": "Camptocamp", + "category": "Finance", + "complexity": "easy", + "depends": ["account_move_base_import", "sale"], + "website": "https://github.com/OCA/account-reconcile", + "data": [ + "data/completion_rule_data.xml", ], - 'installable': True, - 'auto_install': False, - 'license': 'AGPL-3', + "installable": True, + "auto_install": False, + "license": "AGPL-3", } diff --git a/account_move_so_import/data/completion_rule_data.xml b/account_move_so_import/data/completion_rule_data.xml index 7ef4271c..a6701d89 100644 --- a/account_move_so_import/data/completion_rule_data.xml +++ b/account_move_so_import/data/completion_rule_data.xml @@ -1,4 +1,4 @@ - + diff --git a/account_move_so_import/models/__init__.py b/account_move_so_import/models/__init__.py index 8ac192f1..721ad319 100644 --- a/account_move_so_import/models/__init__.py +++ b/account_move_so_import/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2011-2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from . import account_move diff --git a/account_move_so_import/models/account_move.py b/account_move_so_import/models/account_move.py index 4aea64b7..6e3d707a 100644 --- a/account_move_so_import/models/account_move.py +++ b/account_move_so_import/models/account_move.py @@ -1,8 +1,8 @@ # Copyright 2011-2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from odoo import _, fields, models -from odoo.addons.account_move_base_import.models.account_move \ - import ErrorTooManyPartner + +from odoo.addons.account_move_base_import.models.account_move import ErrorTooManyPartner class AccountMoveCompletionRule(models.Model): @@ -11,9 +11,8 @@ class AccountMoveCompletionRule(models.Model): _inherit = "account.move.completion.rule" function_to_call = fields.Selection( - selection_add=[ - ('get_from_name_and_so', 'From line name (based on SO number)') - ]) + selection_add=[("get_from_name_and_so", "From line name (based on SO number)")] + ) # Should be private but data are initialized with no update XML def get_from_name_and_so(self, line): @@ -35,13 +34,16 @@ class AccountMoveCompletionRule(models.Model): ...} """ res = {} - so_obj = self.env['sale.order'] - orders = so_obj.search([('name', '=', line.name)]) + so_obj = self.env["sale.order"] + orders = so_obj.search([("name", "=", line.name)]) if len(orders) > 1: raise ErrorTooManyPartner( - _('Line named "%s" was matched by more ' - 'than one partner while looking on SO by ref.') % - line.name) + _( + 'Line named "%s" was matched by more ' + "than one partner while looking on SO by ref." + ) + % line.name + ) if len(orders) == 1: - res['partner_id'] = orders[0].partner_id.id + res["partner_id"] = orders[0].partner_id.id return res diff --git a/account_move_so_import/tests/test_completion_so.py b/account_move_so_import/tests/test_completion_so.py index 40b614ec..7b3b3053 100644 --- a/account_move_so_import/tests/test_completion_so.py +++ b/account_move_so_import/tests/test_completion_so.py @@ -5,66 +5,91 @@ from odoo.tests.common import SavepointCase class TestCompliteSO(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_1') - p = cls.env.ref('product.product_product_6') - cls.order = cls.env['sale.order'].create({ - 'name': 'Test order', - 'partner_id': cls.partner.id, - 'order_line': [(0, 0, {'name': 'Test autocomplet', - 'product_id': p.id, - 'product_uom_qty': 2, - 'qty_to_invoice': 2, - 'qty_delivered': 2, - 'product_uom': p.uom_id.id, - 'price_unit': p.list_price})], - }) - rule_ids = cls.env.ref('account_move_base_import.' - 'bank_statement_completion_rule_5') - rule_ids += cls.env.ref('account_move_base_import.' - 'bank_statement_completion_rule_4') - rule_ids += cls.env.ref('account_move_base_import.' - 'bank_statement_completion_rule_3') - rule_ids += cls.env.ref('account_move_base_import.' - 'bank_statement_completion_rule_2') - rule_ids += cls.env.ref('account_move_so_import.' - 'bank_statement_completion_rule_1') - # create journal with profile - cls.journal = cls.env['account.journal'].create({ - 'name': 'Company Bank journal', - 'type': 'bank', - 'code': 'BNKFB', - 'rule_ids': [ - (4, comp_rule.id, False) for comp_rule in rule_ids - ], - 'used_for_completion': True, - }) - cls.move = cls.env['account.move'].create( - {'name': 'Test move', 'journal_id': cls.journal.id} + cls.partner = cls.env.ref("base.res_partner_1") + p = cls.env.ref("product.product_product_6") + cls.order = cls.env["sale.order"].create( + { + "name": "Test order", + "partner_id": cls.partner.id, + "order_line": [ + ( + 0, + 0, + { + "name": "Test autocomplet", + "product_id": p.id, + "product_uom_qty": 2, + "qty_to_invoice": 2, + "qty_delivered": 2, + "product_uom": p.uom_id.id, + "price_unit": p.list_price, + }, + ) + ], + } + ) + rule_ids = cls.env.ref( + "account_move_base_import." "bank_statement_completion_rule_5" + ) + rule_ids += cls.env.ref( + "account_move_base_import." "bank_statement_completion_rule_4" + ) + rule_ids += cls.env.ref( + "account_move_base_import." "bank_statement_completion_rule_3" + ) + rule_ids += cls.env.ref( + "account_move_base_import." "bank_statement_completion_rule_2" + ) + rule_ids += cls.env.ref( + "account_move_so_import." "bank_statement_completion_rule_1" + ) + # create journal with profile + cls.journal = cls.env["account.journal"].create( + { + "name": "Company Bank journal", + "type": "bank", + "code": "BNKFB", + "rule_ids": [(4, comp_rule.id, False) for comp_rule in rule_ids], + "used_for_completion": True, + } + ) + cls.move = cls.env["account.move"].create( + {"name": "Test move", "journal_id": cls.journal.id} + ) + cls.account_payable = cls.env["account.account"].search( + [ + ( + "user_type_id", + "=", + cls.env.ref("account.data_account_type_payable").id, + ), + ], + limit=1, ) - cls.account_payable = cls.env['account.account'].search([ - ('user_type_id', '=', - cls.env.ref('account.data_account_type_payable').id), - ], limit=1) def test_completion_so(self): self.order.action_confirm() - aml = self.env['account.move.line'].create( + aml = self.env["account.move.line"].create( { - 'name': self.order.name, - 'account_id': self.account_payable.id, - 'move_id': self.move.id, - 'credit': 0.0, + "name": self.order.name, + "account_id": self.account_payable.id, + "move_id": self.move.id, + "credit": 0.0, + } + ) + aml.with_context(check_move_validity=False).write( + { + "credit": 1, } ) - aml.with_context(check_move_validity=False).write({ - 'credit': 1, - }) self.assertFalse(self.move.partner_id) self.move.button_auto_completion() - self.assertEqual(self.move.partner_id, self.partner,) + self.assertEqual( + self.move.partner_id, + self.partner, + ) diff --git a/setup/account_move_so_import/odoo/addons/account_move_so_import b/setup/account_move_so_import/odoo/addons/account_move_so_import new file mode 120000 index 00000000..f4c4cd20 --- /dev/null +++ b/setup/account_move_so_import/odoo/addons/account_move_so_import @@ -0,0 +1 @@ +../../../../account_move_so_import \ No newline at end of file diff --git a/setup/account_move_so_import/setup.py b/setup/account_move_so_import/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_move_so_import/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)