[MIG] account_move_base_import: Migration to 14.0

This commit is contained in:
Florian da Costa
2021-01-03 16:08:01 +01:00
parent c1c08605d8
commit 4d28d1dd29
11 changed files with 86 additions and 236 deletions

View File

@@ -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"],

View File

@@ -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 = {

View File

@@ -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,

View File

@@ -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
)

View File

@@ -6,7 +6,7 @@
import base64
import csv
from openerp import _, fields
from odoo import _, fields
def UnicodeDictReader(utf8_data, **kwargs):

View File

@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_bank_st_cmpl_user account.move.completion.rule.user model_account_move_completion_rule account.group_account_user 1 0 0 0
3 access_account_bank_st_cmpl_manager account.move.completion.rule.manager model_account_move_completion_rule account.group_account_manager 1 1 1 1
4 access_credit_statement_mport_user credit.statement.import.rule.user model_credit_statement_import account.group_account_user 1 1 1 1

View File

@@ -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}
)

View File

@@ -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,
}
)

View File

@@ -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.

View File

@@ -8,7 +8,7 @@
<field name="journal_id" position="after">
<field name="used_for_completion" invisible="1" />
</field>
<button name="action_duplicate" position="after">
<button name="action_reverse" position="after">
<button
name="button_auto_completion"
string="Auto Completion"
@@ -67,7 +67,7 @@
<field name="view_mode">tree,form</field>
</record>
<menuitem
string="Move Completion Rule"
name="Move Completion Rule"
action="action_move_completion_rule_tree"
id="menu_action_move_completion_rule_tree_menu"
parent="account.account_management_menu"

View File

@@ -64,8 +64,8 @@ class CreditPartnerStatementImporter(models.TransientModel):
moves |= journal.with_context(
file_name=importer.file_name
).multi_move_import(importer.input_statement, ftype.replace(".", ""))
xmlid = ("account", "action_move_journal_line")
action = self.env["ir.actions.act_window"].for_xml_id(*xmlid)
action = action = self.env["ir.actions.actions"]._for_xml_id(
"account.action_move_journal_line")
if len(moves) > 1:
action["domain"] = [("id", "in", moves.ids)]
else: