diff --git a/account_move_base_import/__manifest__.py b/account_move_base_import/__manifest__.py index 59449150..24adbf23 100644 --- a/account_move_base_import/__manifest__.py +++ b/account_move_base_import/__manifest__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) { "name": "Journal Entry base import", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "author": "Akretion,Camptocamp,Odoo Community Association (OCA)", "category": "Finance", "depends": ["account"], diff --git a/account_move_base_import/models/account_journal.py b/account_move_base_import/models/account_journal.py index 089210b1..f2833be2 100644 --- a/account_move_base_import/models/account_journal.py +++ b/account_move_base_import/models/account_journal.py @@ -84,11 +84,11 @@ class AccountJournal(models.Model): def _prepare_counterpart_line(self, move, amount, date): if amount > 0.0: - account_id = self.default_debit_account_id.id + account_id = self.default_account_id.id credit = 0.0 debit = amount else: - account_id = self.default_credit_account_id.id + account_id = self.default_account_id.id credit = -amount debit = 0.0 counterpart_values = { diff --git a/account_move_base_import/models/account_move.py b/account_move_base_import/models/account_move.py index 9e55c059..704fdad4 100644 --- a/account_move_base_import/models/account_move.py +++ b/account_move_base_import/models/account_move.py @@ -86,7 +86,7 @@ class AccountMoveCompletionRule(models.Model): ) invoices = inv_obj.search( - [(number_field, "=", line.name.strip()), ("type", "in", type_domain)] + [(number_field, "=", line.name.strip()), ("move_type", "in", type_domain)] ) if invoices: if len(invoices) == 1: @@ -169,6 +169,7 @@ class AccountMoveCompletionRule(models.Model): res = {} partner_obj = self.env["res.partner"] or_regex = ".*;? *%s *;?.*" % line.name + self.env["res.partner"].flush(["bank_statement_label"]) sql = "SELECT id from res_partner" " WHERE bank_statement_label ~* %s" self.env.cr.execute(sql, (or_regex,)) partner_ids = self.env.cr.fetchall() @@ -207,6 +208,7 @@ class AccountMoveCompletionRule(models.Model): # to: # http://www.postgresql.org/docs/9.0/static/functions-matching.html # in chapter 9.7.3.6. Limits and Compatibility + self.env["res.partner"].flush(["name"]) sql = r""" SELECT id FROM ( SELECT id, diff --git a/account_move_base_import/parser/file_parser.py b/account_move_base_import/parser/file_parser.py index 12122ea4..086df420 100644 --- a/account_move_base_import/parser/file_parser.py +++ b/account_move_base_import/parser/file_parser.py @@ -123,7 +123,7 @@ class FileParser(AccountMoveImportParser): csv_file = tempfile.NamedTemporaryFile() csv_file.write(self.filebuffer) csv_file.flush() - with open(csv_file.name, "rU") as fobj: + with open(csv_file.name, "r") as fobj: reader = UnicodeDictReader( fobj, fieldnames=self.fieldnames, dialect=self.dialect ) diff --git a/account_move_base_import/parser/parser.py b/account_move_base_import/parser/parser.py index e81c50b4..e88cca30 100644 --- a/account_move_base_import/parser/parser.py +++ b/account_move_base_import/parser/parser.py @@ -6,7 +6,7 @@ import base64 import csv -from openerp import _, fields +from odoo import _, fields def UnicodeDictReader(utf8_data, **kwargs): diff --git a/account_move_base_import/security/ir.model.access.csv b/account_move_base_import/security/ir.model.access.csv index f1bdb6c1..0da20fb3 100644 --- a/account_move_base_import/security/ir.model.access.csv +++ b/account_move_base_import/security/ir.model.access.csv @@ -1,3 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_account_bank_st_cmpl_user,account.move.completion.rule.user,model_account_move_completion_rule,account.group_account_user,1,0,0,0 access_account_bank_st_cmpl_manager,account.move.completion.rule.manager,model_account_move_completion_rule,account.group_account_manager,1,1,1,1 +access_credit_statement_mport_user,credit.statement.import.rule.user,model_credit_statement_import,account.group_account_user,1,1,1,1 diff --git a/account_move_base_import/tests/test_base_completion.py b/account_move_base_import/tests/test_base_completion.py index 27f5695a..8a8d4ecc 100644 --- a/account_move_base_import/tests/test_base_completion.py +++ b/account_move_base_import/tests/test_base_completion.py @@ -5,9 +5,10 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) from collections import namedtuple -from odoo import fields, tools -from odoo.modules import get_resource_path -from odoo.tests import common +import odoo.tests +from odoo import fields + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon name_completion_case = namedtuple( "name_completion_case", ["partner_name", "line_label", "should_match"] @@ -39,24 +40,16 @@ NAMES_COMPLETION_CASES = [ ] -class BaseCompletion(common.TransactionCase): - def setUp(self): - super().setUp() - tools.convert_file( - self.cr, - "account", - get_resource_path("account", "test", "account_minimal_test.xml"), - {}, - "init", - False, - "test", - ) - self.account_move_obj = self.env["account.move"] - self.account_move_line_obj = self.env["account.move.line"] - self.company_a = self.browse_ref("base.main_company") - self.journal = self.browse_ref("account.bank_journal") - self.partner = self.browse_ref("base.res_partner_12") - self.account_id = self.ref("account.a_recv") +@odoo.tests.tagged("post_install", "-at_install") +class BaseCompletion(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.account_move_obj = cls.env["account.move"] + cls.account_move_line_obj = cls.env["account.move.line"] + cls.journal = cls.company_data["default_journal_bank"] + cls.partner = cls.env.ref("base.res_partner_12") + cls.account_id = cls.journal.default_account_id.id def test_name_completion(self): """Test complete partner_id from statement line label @@ -73,7 +66,7 @@ class BaseCompletion(common.TransactionCase): "rule_ids": [(6, 0, [self.completion_rule_id])], } ) - # Create a bank statement + # Create an account move self.move = self.account_move_obj.create( {"date": fields.Date.today(), "journal_id": self.journal.id} ) diff --git a/account_move_base_import/tests/test_base_import.py b/account_move_base_import/tests/test_base_import.py index 5d52f904..fee9a2e7 100644 --- a/account_move_base_import/tests/test_base_import.py +++ b/account_move_base_import/tests/test_base_import.py @@ -7,37 +7,31 @@ import base64 import os from operator import attrgetter -from odoo import fields, tools +import odoo.tests +from odoo import fields from odoo.modules import get_resource_path -from odoo.tests import common + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon -class TestCodaImport(common.TransactionCase): - def setUp(self): - super().setUp() - self.company_a = self.browse_ref("base.main_company") - tools.convert_file( - self.cr, - "account", - get_resource_path("account", "test", "account_minimal_test.xml"), - {}, - "init", - False, - "test", - ) - self.account_move_obj = self.env["account.move"] - self.account_move_line_obj = self.env["account.move.line"] - self.account_id = self.ref("account.a_recv") - self.journal = self.browse_ref("account.bank_journal") - self.import_wizard_obj = self.env["credit.statement.import"] - self.partner = self.browse_ref("base.res_partner_12") - self.journal.write( +@odoo.tests.tagged("post_install", "-at_install") +class TestCodaImport(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.account_move_obj = cls.env["account.move"] + cls.account_move_line_obj = cls.env["account.move.line"] + cls.journal = cls.company_data["default_journal_bank"] + cls.partner = cls.env.ref("base.res_partner_12") + cls.account_id = cls.journal.default_account_id.id + cls.import_wizard_obj = cls.env["credit.statement.import"] + cls.journal.write( { "used_for_import": True, "import_type": "generic_csvxls_so", - "partner_id": self.partner.id, - "commission_account_id": self.account_id, - "receivable_account_id": self.account_id, + "partner_id": cls.partner.id, + "commission_account_id": cls.account_id, + "receivable_account_id": cls.account_id, "create_counterpart": True, } ) diff --git a/account_move_base_import/tests/test_invoice.py b/account_move_base_import/tests/test_invoice.py index a2ead190..8c50697a 100644 --- a/account_move_base_import/tests/test_invoice.py +++ b/account_move_base_import/tests/test_invoice.py @@ -1,195 +1,51 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +import odoo.tests from odoo import fields -from odoo.modules import get_resource_path -from odoo.tests import SingleTransactionCase -from odoo.tools import convert_file + +from odoo.addons.account.tests.common import TestAccountReconciliationCommon -class TestInvoice(SingleTransactionCase): - def setUp(self): - super().setUp() - self.account_move_obj = self.env["account.move"] - self.account_move_line_obj = self.env["account.move.line"] - self.company_a = self.env.ref("base.main_company") - self.partner = self.env.ref("base.res_partner_12") +@odoo.tests.tagged("post_install", "-at_install") +class TestInvoice(TestAccountReconciliationCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.account_move_obj = cls.env["account.move"] + cls.account_move_line_obj = cls.env["account.move.line"] + cls.journal = cls.company_data["default_journal_bank"] + cls.account_id = cls.journal.default_account_id.id - def test_01_partner(self): + def test_all_completion_rules(self): # I fill in the field Bank Statement Label in a Partner self.partner_4 = self.env.ref("base.res_partner_4") self.partner_4.bank_statement_label = "XXX66Z" self.assertEqual(self.partner_4.bank_statement_label, "XXX66Z") - def test_02_invoice(self): - convert_file( - self.cr, - "account", - get_resource_path("account", "test", "account_minimal_test.xml"), - {}, - "init", - False, - "test", + self.invoice_for_completion_1 = self._create_invoice( + date_invoice=fields.Date.today(), auto_validate=True ) - self.journal = self.env.ref("account.bank_journal") - self.account_id = self.env.ref("account.a_recv") - # I create a customer Invoice to be found by the completion. - product_3 = self.env.ref("product.product_product_3") - self.invoice_for_completion_1 = ( - self.env["account.move"] - .with_context(default_type="out_invoice") - .create( - { - "currency_id": self.env.ref("base.EUR").id, - "type": "out_invoice", - "invoice_line_ids": [ - ( - 0, - 0, - { - "name": "[PCSC234] PC Assemble SC234", - "product_id": product_3.id, - "price_unit": 210.0, - "quantity": 1.0, - "product_uom_id": self.env.ref( - "uom.product_uom_unit" - ).id, - "account_id": self.env.ref("account.a_sale").id, - }, - ) - ], - "journal_id": self.journal.id, - "partner_id": self.partner.id, - } - ) - ) - # I confirm the Invoice - self.invoice_for_completion_1.post() - # I check that the invoice state is "Open" self.assertEqual(self.invoice_for_completion_1.state, "posted") - # I check that it is given the number "TBNK/%Y/0001" self.assertEqual( self.invoice_for_completion_1.name, - fields.Date.today().strftime("TBNK/%Y/0001"), + fields.Date.today().strftime("INV/%Y/%m/0001"), ) - def test_03_supplier_invoice(self): - # I create a demo invoice - product_delivery = self.env.ref("product.product_delivery_01") - product_order = self.env.ref("product.product_order_01") - exp_account = self.env.ref("account.a_expense") - demo_invoice_0 = ( - self.env["account.move"] - .with_context(default_type="in_invoice") - .create( - { - "partner_id": self.partner.id, - "invoice_payment_term_id": self.env.ref( - "account.account_payment_term_advance" - ).id, - "type": "in_invoice", - "invoice_date": fields.Date.today().replace(day=1), - "invoice_line_ids": [ - ( - 0, - 0, - { - "price_unit": 10.0, - "quantity": 1.0, - "product_id": product_delivery.id, - "product_uom_id": self.env.ref( - "uom.product_uom_unit" - ).id, - "name": product_delivery.name, - "account_id": exp_account.id, - }, - ), - ( - 0, - 0, - { - "price_unit": 4.0, - "quantity": 1.0, - "product_id": product_order.id, - "name": product_order.name, - "product_uom_id": self.env.ref( - "uom.product_uom_unit" - ).id, - "account_id": exp_account.id, - }, - ), - ], - } - ) + self.demo_invoice_0 = self._create_invoice( + move_type="in_invoice", auto_validate=True ) + self.demo_invoice_0.ref = "T2S12345" - # I check that my invoice is a supplier invoice - self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type") - # I add a reference to an existing supplier invoice - demo_invoice_0.write({"ref": "T2S12345"}) - # I check a second time that my invoice is still a supplier invoice - self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 2") - # Now I confirm it - demo_invoice_0.post() - # I check that the supplier number is there - self.assertEqual(demo_invoice_0.ref, "T2S12345", msg="Check supplier number") - # I check a third time that my invoice is still a supplier invoice - self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 3") - - def test_04_refund(self): - # I create a "child" partner, to use in the invoice - # (and have a different commercial_partner_id than itself) - res_partner_12_child = self.env["res.partner"].create( - { - "name": "Child Partner", - "is_company": False, - "parent_id": self.partner.id, - } + self.refund_for_completion_1 = self._create_invoice( + move_type="out_refund", date_invoice=fields.Date.today(), auto_validate=True ) - # I create a customer refund to be found by the completion. - product_3 = self.env.ref("product.product_product_3") - self.refund_for_completion_1 = ( - self.env["account.move"] - .with_context(default_type="out_refund") - .create( - { - "currency_id": self.env.ref("base.EUR").id, - "invoice_line_ids": [ - ( - 0, - 0, - { - "name": "[PCSC234] PC Assemble SC234", - "product_id": product_3.id, - "price_unit": 210.0, - "quantity": 1.0, - "product_uom_id": self.env.ref( - "uom.product_uom_unit" - ).id, - "account_id": self.env.ref("account.a_sale").id, - }, - ) - ], - "journal_id": self.env.ref("account.expenses_journal").id, - "partner_id": res_partner_12_child.id, - "type": "out_refund", - } - ) - ) - # I confirm the refund - self.refund_for_completion_1.post() - - # I check that the refund state is "Open" - self.assertEqual(self.refund_for_completion_1.state, "posted") - # I check that it is given the number "RTEXJ/%Y/0001" self.assertEqual( self.refund_for_completion_1.name, - fields.Date.today().strftime("RTEXJ/%Y/0001"), + fields.Date.today().strftime("RINV/%Y/%m/0001"), ) - def test_05_completion(self): # In order to test the banking framework, I first need to create a # journal - self.journal = self.env.ref("account.bank_journal") completion_rule_4 = self.env.ref( "account_move_base_import.bank_statement_completion_rule_4" ) @@ -230,7 +86,7 @@ class TestInvoice(SingleTransactionCase): .create( { "name": "\\", - "account_id": self.env.ref("account.a_sale").id, + "account_id": self.company_data["default_account_receivable"].id, "move_id": move_test1.id, "date_maturity": fields.Date.from_string("2013-12-20"), "credit": 0.0, @@ -244,7 +100,7 @@ class TestInvoice(SingleTransactionCase): .create( { "name": "\\", - "account_id": self.env.ref("account.a_expense").id, + "account_id": self.company_data["default_account_expense"].id, "move_id": move_test1.id, "date_maturity": fields.Date.from_string("2013-12-19"), "debit": 0.0, @@ -258,7 +114,7 @@ class TestInvoice(SingleTransactionCase): .create( { "name": "\\", - "account_id": self.env.ref("account.a_expense").id, + "account_id": self.company_data["default_account_expense"].id, "move_id": move_test1.id, "date_maturity": fields.Date.from_string("2013-12-19"), "debit": 0.0, @@ -271,8 +127,8 @@ class TestInvoice(SingleTransactionCase): .with_context(check_move_validity=False) .create( { - "name": "Test autocompletion based on Partner Name Azure Interior", - "account_id": self.env.ref("account.a_sale").id, + "name": "Test autocompletion based on Partner Name Deco Addict", + "account_id": self.company_data["default_account_receivable"].id, "move_id": move_test1.id, "date_maturity": fields.Date.from_string("2013-12-17"), "credit": 0.0, @@ -286,7 +142,7 @@ class TestInvoice(SingleTransactionCase): .create( { "name": "XXX66Z", - "account_id": self.env.ref("account.a_sale").id, + "account_id": self.company_data["default_account_receivable"].id, "move_id": move_test1.id, "date_maturity": "2013-12-24", "debit": 0.0, @@ -295,13 +151,13 @@ class TestInvoice(SingleTransactionCase): ) # and add the correct name move_line_ci.with_context(check_move_validity=False).write( - {"name": fields.Date.today().strftime("TBNK/%Y/0001"), "credit": 210.0} + {"name": fields.Date.today().strftime("INV/%Y/%m/0001"), "credit": 210.0} ) move_line_si.with_context(check_move_validity=False).write( {"name": "T2S12345", "debit": 65.0} ) move_line_cr.with_context(check_move_validity=False).write( - {"name": fields.Date.today().strftime("RTEXJ/%Y/0001"), "debit": 210.0} + {"name": fields.Date.today().strftime("RINV/%Y/%m/0001"), "debit": 210.0} ) move_line_partner_name.with_context(check_move_validity=False).write( {"credit": 600.0} @@ -316,25 +172,29 @@ class TestInvoice(SingleTransactionCase): # I Use _ref, because ref conflicts with the field ref of the # statement line self.assertEqual( - move_line_ci.partner_id, self.partner, msg="Check completion by CI number" + move_line_ci.partner_id.id, + self.partner_agrolait_id, + msg="Check completion by CI number", ) # Line 2. I expect the Supplier invoice number to be recognised. The # supplier invoice was created by the account module demo data, and we # confirmed it here. self.assertEqual( - move_line_si.partner_id, self.partner, msg="Check completion by SI number" + move_line_si.partner_id.id, + self.partner_agrolait_id, + msg="Check completion by SI number", ) # Line 3. I expect the Customer refund number to be recognised. It # should be the commercial partner, and not the regular partner. self.assertEqual( - move_line_cr.partner_id, - self.partner, + move_line_cr.partner_id.id, + self.partner_agrolait_id, msg="Check completion by CR number and commercial partner", ) # Line 4. I check that the partner name has been recognised. self.assertEqual( move_line_partner_name.partner_id.name, - "Azure Interior", + "Deco Addict", msg="Check completion by partner name", ) # Line 5. I check that the partner special label has been recognised. diff --git a/account_move_base_import/views/account_move_view.xml b/account_move_base_import/views/account_move_view.xml index 5a4257d9..46df5ebf 100644 --- a/account_move_base_import/views/account_move_view.xml +++ b/account_move_base_import/views/account_move_view.xml @@ -8,7 +8,7 @@ -