From 99825230fee9f68385b49be327cd9ddaca8fb948 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Thu, 11 Jul 2019 15:09:49 +0200 Subject: [PATCH] [MIG] account_move_transactionid_import to 12.0 --- account_move_transactionid_import/__init__.py | 1 - .../__manifest__.py | 11 +- .../models/__init__.py | 1 - .../models/account_journal.py | 5 +- .../models/account_move.py | 10 +- .../parser/__init__.py | 1 - .../parser/transactionid_file_parser.py | 9 +- .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 4 + .../completion_invoice_transactionid_test.yml | 44 ------ .../test/completion_transactionid_test.yml | 48 ------ .../test/invoice.yml | 25 --- .../test/sale.yml | 21 --- .../tests/__init__.py | 1 + .../tests/test_completion_transaction_id.py | 147 ++++++++++++++++++ 15 files changed, 166 insertions(+), 164 deletions(-) create mode 100644 account_move_transactionid_import/readme/CONTRIBUTORS.rst create mode 100644 account_move_transactionid_import/readme/DESCRIPTION.rst delete mode 100644 account_move_transactionid_import/test/completion_invoice_transactionid_test.yml delete mode 100644 account_move_transactionid_import/test/completion_transactionid_test.yml delete mode 100644 account_move_transactionid_import/test/invoice.yml delete mode 100644 account_move_transactionid_import/test/sale.yml create mode 100644 account_move_transactionid_import/tests/__init__.py create mode 100644 account_move_transactionid_import/tests/test_completion_transaction_id.py diff --git a/account_move_transactionid_import/__init__.py b/account_move_transactionid_import/__init__.py index 728557cc..6f860c64 100644 --- a/account_move_transactionid_import/__init__.py +++ b/account_move_transactionid_import/__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 parser diff --git a/account_move_transactionid_import/__manifest__.py b/account_move_transactionid_import/__manifest__.py index 370d34d7..e4ba6bb3 100644 --- a/account_move_transactionid_import/__manifest__.py +++ b/account_move_transactionid_import/__manifest__.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # © 2011-2016 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) { 'name': "Journal Entry transactionID import", - 'version': '9.0.1.0.0', + 'version': '12.0.1.0.0', 'author': "Camptocamp,Odoo Community Association (OCA)", 'maintainer': 'Camptocamp', 'category': 'Finance', @@ -15,14 +14,8 @@ 'data': [ 'data/completion_rule_data.xml' ], - 'test': [ - 'test/sale.yml', - 'test/completion_transactionid_test.yml', - 'test/invoice.yml', - 'test/completion_invoice_transactionid_test.yml', - ], 'website': 'http://www.camptocamp.com', - 'installable': False, + 'installable': True, 'auto_install': False, 'license': 'AGPL-3', } diff --git a/account_move_transactionid_import/models/__init__.py b/account_move_transactionid_import/models/__init__.py index 079b873d..431266db 100644 --- a/account_move_transactionid_import/models/__init__.py +++ b/account_move_transactionid_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_journal diff --git a/account_move_transactionid_import/models/account_journal.py b/account_move_transactionid_import/models/account_journal.py index 3ddda9f9..919d2490 100644 --- a/account_move_transactionid_import/models/account_journal.py +++ b/account_move_transactionid_import/models/account_journal.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- -# © 2011-2016 Camptocamp SA +# © 2011-2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from openerp import fields, models +from odoo import fields, models class AccountJournal(models.Model): diff --git a/account_move_transactionid_import/models/account_move.py b/account_move_transactionid_import/models/account_move.py index 6880abee..b4344029 100644 --- a/account_move_transactionid_import/models/account_move.py +++ b/account_move_transactionid_import/models/account_move.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- -# © 2011-2016 Camptocamp SA +# © 2011-2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from openerp import _, fields, models -from openerp.addons.account_move_base_import.models.account_move import \ +from odoo import _, fields, models +from odoo.addons.account_move_base_import.models.account_move import \ ErrorTooManyPartner @@ -41,8 +40,7 @@ class AccountMoveCompletionRule(models.Model): _('Line named "%s" was matched by more than ' 'one partner.') % line.name) if len(sales) == 1: - sale = sales[0] - res['partner_id'] = sale.partner_id.id + res['partner_id'] = sales[0].partner_id.id return res def get_from_transaction_id_and_invoice(self, line): diff --git a/account_move_transactionid_import/parser/__init__.py b/account_move_transactionid_import/parser/__init__.py index 9102553c..f8a86141 100644 --- a/account_move_transactionid_import/parser/__init__.py +++ b/account_move_transactionid_import/parser/__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 transactionid_file_parser diff --git a/account_move_transactionid_import/parser/transactionid_file_parser.py b/account_move_transactionid_import/parser/transactionid_file_parser.py index 12e66040..e57b4366 100644 --- a/account_move_transactionid_import/parser/transactionid_file_parser.py +++ b/account_move_transactionid_import/parser/transactionid_file_parser.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -# © 2011-2016 Camptocamp SA +# © 2011-2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) import datetime -from openerp.tools import ustr -from openerp.addons.account_move_base_import.parser.file_parser import ( +from odoo.tools import ustr +from odoo.addons.account_move_base_import.parser.file_parser import ( FileParser, float_or_zero ) @@ -30,7 +29,7 @@ class TransactionIDFileParser(FileParser): 'amount': float_or_zero, 'commission_amount': float_or_zero, } - super(TransactionIDFileParser, self).__init__( + super().__init__( profile, extra_fields=conversion_dict, ftype=ftype, header=header, **kwargs) diff --git a/account_move_transactionid_import/readme/CONTRIBUTORS.rst b/account_move_transactionid_import/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..ddef6481 --- /dev/null +++ b/account_move_transactionid_import/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Joël Grand-Guillaume +* Matthieu Dietrich diff --git a/account_move_transactionid_import/readme/DESCRIPTION.rst b/account_move_transactionid_import/readme/DESCRIPTION.rst new file mode 100644 index 00000000..bd23488e --- /dev/null +++ b/account_move_transactionid_import/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module extends the functionality of +account_move_base_import, in order to add both importation +and auto-completion for the "transaction_ref" field added in +base_transaction_id. diff --git a/account_move_transactionid_import/test/completion_invoice_transactionid_test.yml b/account_move_transactionid_import/test/completion_invoice_transactionid_test.yml deleted file mode 100644 index ebfc3206..00000000 --- a/account_move_transactionid_import/test/completion_invoice_transactionid_test.yml +++ /dev/null @@ -1,44 +0,0 @@ -- - In order to test the banking framework, I first need to create a journal -- - !record {model: account.journal, id: account.bank_journal}: - used_for_completion: True - rule_ids: - - bank_statement_completion_rule_trans_id_invoice -- - Now I create a move. I create statment lines separately because I need - to find each one by XML id -- - !record {model: account.move, id: move_invoice_transactionid_test1}: - name: Move with transaction ID - journal_id: account.bank_journal - company_id: base.main_company -- - I create a move line for a SO with transaction ID -- - !record {model: account.move.line, id: move_line_invoice_transactionid}: - name: Test autocompletion based on invoice with transaction ID - account_id: account.a_sale - move_id: move_invoice_transactionid_test1 - transaction_ref: XXX77Z - date_maturity: !eval time.strftime('%Y-%m-%d') - credit: 0.0 -- - and add the correct amount -- - !python {model: account.move.line}: | - context['check_move_validity'] = False - model.write(cr, uid, [ref('move_line_invoice_transactionid')], - {'credit': 450.0}, - context) -- - I run the auto complete -- - !python {model: account.move}: | - result = self.button_auto_completion(cr, uid, [ref("move_invoice_transactionid_test1")]) -- - Now I can check that all is nice and shiny, line 1. I expect the invoice has been - recognised from the transaction ID. -- - !assert {model: account.move.line, id: move_line_invoice_transactionid, string: Check completion by Invoice transaction ID}: - - partner_id.name == u'Agrolait' diff --git a/account_move_transactionid_import/test/completion_transactionid_test.yml b/account_move_transactionid_import/test/completion_transactionid_test.yml deleted file mode 100644 index b96acf2e..00000000 --- a/account_move_transactionid_import/test/completion_transactionid_test.yml +++ /dev/null @@ -1,48 +0,0 @@ -- - In order to test the banking framework, I first need to create a journal -- - !record {model: account.journal, id: account.bank_journal}: - used_for_completion: True - rule_ids: - - bank_statement_completion_rule_4 - - account_move_base_import.bank_statement_completion_rule_4 - - account_move_base_import.bank_statement_completion_rule_5 - - account_move_base_import.bank_statement_completion_rule_2 - - account_move_base_import.bank_statement_completion_rule_3 -- - Now I create a move. I create statment lines separately because I need - to find each one by XML id -- - !record {model: account.move, id: move_transactionid_test1}: - name: Move with transaction ID - journal_id: account.bank_journal - company_id: base.main_company -- - I create a move line for a SO with transaction ID -- - !record {model: account.move.line, id: move_line_transactionid}: - name: Test autocompletion based on SO with transaction ID - account_id: account.a_sale - move_id: move_transactionid_test1 - transaction_ref: XXX66Z - date_maturity: !eval "'%s-01-06' %(datetime.now().year)" - credit: 0.0 -- - and add the correct amount -- - !python {model: account.move.line}: | - context['check_move_validity'] = False - model.write(cr, uid, [ref('move_line_transactionid')], - {'credit': 118.4}, - context) -- - I run the auto complete -- - !python {model: account.move}: | - result = self.button_auto_completion(cr, uid, [ref("move_transactionid_test1")]) -- - Now I can check that all is nice and shiny, line 1. I expect the SO has been - recognised from the transaction ID. -- - !assert {model: account.move.line, id: move_line_transactionid, string: Check completion by SO transaction ID}: - - partner_id.name == u'Agrolait' diff --git a/account_move_transactionid_import/test/invoice.yml b/account_move_transactionid_import/test/invoice.yml deleted file mode 100644 index 61c10aa2..00000000 --- a/account_move_transactionid_import/test/invoice.yml +++ /dev/null @@ -1,25 +0,0 @@ -- - I create a new invoice with transaction ID -- - !record {model: account.invoice, id: invoice_with_transaction_id}: - company_id: base.main_company - currency_id: base.EUR - partner_id: base.res_partner_2 - transaction_id: XXX77Z - invoice_line_ids: - - name: '[PCSC234] PC Assemble SC234' - price_unit: 450.0 - quantity: 1.0 - product_id: product.product_product_3 - uom_id: product.product_uom_unit - journal_id: account.bank_journal - reference_type: none -- - I confirm the Invoice -- - !workflow {model: account.invoice, action: invoice_open, ref: invoice_with_transaction_id} -- - I check that the invoice state is "Open" -- - !assert {model: account.invoice, id: invoice_with_transaction_id}: - - state == 'open' diff --git a/account_move_transactionid_import/test/sale.yml b/account_move_transactionid_import/test/sale.yml deleted file mode 100644 index d712f8ad..00000000 --- a/account_move_transactionid_import/test/sale.yml +++ /dev/null @@ -1,21 +0,0 @@ -- - I import account minimal data -- - !python {model: account.invoice}: | - openerp.tools.convert_file(cr, - 'account', - openerp.modules.get_module_resource( - 'account', - 'test', - 'account_minimal_test.xml'), - {}, 'init', False, 'test') -- - I create a new Sale Order with transaction ID -- - !record {model: sale.order, id: so_with_transaction_id}: - partner_id: base.res_partner_2 - note: Invoice after delivery - transaction_id: XXX66Z - order_line: - - product_id: product.product_product_7 - product_uom_qty: 8 diff --git a/account_move_transactionid_import/tests/__init__.py b/account_move_transactionid_import/tests/__init__.py new file mode 100644 index 00000000..f14d0f36 --- /dev/null +++ b/account_move_transactionid_import/tests/__init__.py @@ -0,0 +1 @@ +from . import test_completion_transaction_id diff --git a/account_move_transactionid_import/tests/test_completion_transaction_id.py b/account_move_transactionid_import/tests/test_completion_transaction_id.py new file mode 100644 index 00000000..f8029f3d --- /dev/null +++ b/account_move_transactionid_import/tests/test_completion_transaction_id.py @@ -0,0 +1,147 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from datetime import datetime +from odoo.modules import get_resource_path +from odoo.tests import SingleTransactionCase +from odoo.tools import convert_file + + +class TestCompletionTransactionId(SingleTransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + convert_file( + cls.cr, + 'account', + get_resource_path('account', 'test', 'account_minimal_test.xml'), + {}, + 'init', + False, + 'test', + ) + cls.partner = cls.env.ref('base.res_partner_2') + cls.journal = cls.env.ref('account.bank_journal') + cls.journal.used_for_completion = True + cls.move = cls.env['account.move'].create( + {'name': 'Move with transaction ID', 'journal_id': cls.journal.id} + ) + cls.move_line = cls.env['account.move.line'].create( + { + 'name': 'Test autocompletion on invoice with transaction ID', + 'account_id': cls.env.ref('account.a_sale').id, + 'move_id': cls.move.id, + 'transaction_ref': 'XXX66Z', + 'date_maturity': '{}-01-06'.format(datetime.now().year), + 'credit': 0.0, + } + ) + + def test_sale_order_transaction_id(self): + self.move_line.transaction_ref = 'XXX66Z' + self.journal.rule_ids = [ + ( + 4, + self.env.ref( + 'account_move_transactionid_import.' + 'bank_statement_completion_rule_4' + ).id, + False, + ), + ( + 4, + self.env.ref( + 'account_move_base_import.bank_statement_completion_rule_2' + ).id, + False, + ), + ( + 4, + self.env.ref( + 'account_move_base_import.bank_statement_completion_rule_3' + ).id, + False, + ), + ( + 4, + self.env.ref( + 'account_move_base_import.bank_statement_completion_rule_4' + ).id, + False, + ), + ( + 4, + self.env.ref( + 'account_move_base_import.bank_statement_completion_rule_5' + ).id, + False, + ), + ] + self.move_line.with_context({'check_move_validity': False}).write( + {'credit': 118.4} + ) + so = self.env['sale.order'].create( + { + 'partner_id': self.partner.id, + 'note': 'Invoice after delivery', + 'transaction_id': 'XXX66Z', + 'order_line': [ + ( + 0, + 0, + { + 'product_id': self.env.ref( + 'product.product_product_7' + ).id, + 'product_uom_qty': 8, + }, + ) + ], + } + ) + self.assertEqual(so.transaction_id, 'XXX66Z') + self.move.button_auto_completion() + self.assertEqual(self.move_line.partner_id.name, self.partner.name) + + def test_new_invoice_with_transaction_id(self): + self.move_line.transaction_ref = 'XXX77Z' + self.move_line.partner_id = None + self.journal.rule_ids = [ + ( + 4, + self.env.ref( + 'account_move_transactionid_import.' + 'bank_statement_completion_rule_trans_id_invoice' + ).id, + False, + ) + ] + invoice = self.env['account.invoice'].create( + { + 'currency_id': self.env.ref('base.EUR').id, + 'partner_id': self.partner.id, + 'transaction_id': 'XXX77Z', + 'reference_type': None, + 'journal_id': self.journal.id, + 'invoice_line_ids': [ + ( + 0, + 0, + { + 'name': '[PCSC234] PC Assemble SC234', + 'price_unit': 450.0, + 'quantity': 1.0, + 'product_id': self.env.ref( + 'product.product_product_3' + ).id, + 'uom_id': self.env.ref('uom.product_uom_unit').id, + 'account_id': self.env.ref('account.a_sale').id, + }, + ) + ], + } + ) + invoice.action_invoice_open() + self.assertEqual(invoice.state, 'open') + self.move.button_auto_completion() + self.assertEqual(self.move_line.partner_id, self.partner)