Skip to content

Commit b259e30

Browse files
committed
[MIG] account_invoice_import: Migration to 16.0
1 parent da4ab84 commit b259e30

File tree

10 files changed

+487
-208
lines changed

10 files changed

+487
-208
lines changed

account_invoice_import/README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Account Invoice Import
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
20-
:target: https://github.com/OCA/edi/tree/14.0/account_invoice_import
20+
:target: https://github.com/OCA/edi/tree/16.0/account_invoice_import
2121
:alt: OCA/edi
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import
23+
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=14.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -99,7 +99,7 @@ Bug Tracker
9999
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
100100
In case of trouble, please check there if your issue has already been reported.
101101
If you spotted it first, help us to smash it by providing a detailed and welcomed
102-
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
102+
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
103103

104104
Do not contact contributors directly about support or help with technical issues.
105105

@@ -142,6 +142,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
142142

143143
|maintainer-alexis-via|
144144

145-
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/account_invoice_import>`_ project on GitHub.
145+
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/account_invoice_import>`_ project on GitHub.
146146

147147
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_invoice_import/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{
66
"name": "Account Invoice Import",
7-
"version": "14.0.3.4.0",
7+
"version": "16.0.1.0.0",
88
"category": "Accounting & Finance",
99
"license": "AGPL-3",
1010
"summary": "Import supplier invoices/refunds as PDF or XML files",

account_invoice_import/static/description/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Account Invoice Import</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:26f0853d4122605d020e48687fa420f66fdad1a6c7e41efe74059e0a845f5348
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module has been started by lazy accounting users who hate enter they vendor bills manually in Odoo. Almost all companies have several vendor bills to enter regularly in the system from the same vendors: phone bill, electricity bill, Internet access, train tickets, etc. Most of these invoices are available as PDF. If we are able to automatically extract from the PDF the required information to enter the invoice as vendor bill in Odoo, then this module will create it automatically. To know the full story behind the development of this module, read this <a class="reference external" href="http://www.akretion.com/blog/akretions-christmas-present-for-the-odoo-community">blog post</a>.</p>
374374
<p>In order to reliably extract the required information from the invoice, two international standards exists to describe an Invoice in XML:</p>
375375
<ul class="simple">
@@ -441,7 +441,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
441441
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi/issues">GitHub Issues</a>.
442442
In case of trouble, please check there if your issue has already been reported.
443443
If you spotted it first, help us to smash it by providing a detailed and welcomed
444-
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
444+
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
445445
<p>Do not contact contributors directly about support or help with technical issues.</p>
446446
</div>
447447
<div class="section" id="credits">
@@ -474,7 +474,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
474474
promote its widespread use.</p>
475475
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
476476
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
477-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
477+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
478478
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
479479
</div>
480480
</div>

account_invoice_import/tests/test_invoice_import.py

+120-93
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,50 @@
44
# @author: Simone Orsi <simahawk@gmail.com>
55
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
66

7-
import logging
8-
from unittest import mock
7+
from contextlib import contextmanager
8+
from logging import getLogger
99

10-
from odoo import fields
11-
from odoo.tests.common import SavepointCase
10+
from odoo import api, fields
11+
from odoo.tests.common import TransactionCase
1212
from odoo.tools import file_open, float_is_zero
1313

14-
logger = logging.getLogger(__name__)
14+
logger = getLogger(__name__)
1515

1616

17-
class TestInvoiceImport(SavepointCase):
17+
class TestInvoiceImport(TransactionCase):
1818
@classmethod
1919
def setUpClass(cls):
2020
super().setUpClass()
2121
cls.company = cls.env.ref("base.main_company")
2222
cls.company.invoice_import_email = "alexis.delattre@testme.com"
2323
cls.expense_account = cls.env["account.account"].create(
24-
{
25-
"code": "612AII",
26-
"name": "expense account invoice import",
27-
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
28-
"company_id": cls.company.id,
29-
}
24+
[
25+
{
26+
"code": "612AII",
27+
"name": "expense account invoice import",
28+
"account_type": "expense",
29+
"company_id": cls.company.id,
30+
}
31+
]
3032
)
3133
cls.income_account = cls.env["account.account"].create(
32-
{
33-
"code": "707AII",
34-
"name": "revenue account invoice import",
35-
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
36-
"company_id": cls.company.id,
37-
}
34+
[
35+
{
36+
"code": "707AII",
37+
"name": "revenue account invoice import",
38+
"account_type": "income",
39+
"company_id": cls.company.id,
40+
}
41+
]
3842
)
3943
cls.adjustment_account = cls.env["account.account"].create(
40-
{
41-
"code": "Adjustment",
42-
"name": "adjustment from invoice import",
43-
"user_type_id": cls.env.ref(
44-
"account.data_account_type_current_assets"
45-
).id,
46-
}
44+
[
45+
{
46+
"code": "Adjustment",
47+
"name": "adjustment from invoice import",
48+
"account_type": "asset_current",
49+
}
50+
]
4751
)
4852
purchase_tax_vals = {
4953
"name": "Test 1% VAT Purchase",
@@ -54,11 +58,12 @@ def setUpClass(cls):
5458
"unece_type_id": cls.env.ref("account_tax_unece.tax_type_vat").id,
5559
"unece_categ_id": cls.env.ref("account_tax_unece.tax_categ_s").id,
5660
"company_id": cls.company.id,
61+
"country_id": cls.env.ref("base.us").id,
5762
# TODO tax armageddon
5863
# "account_id": cls.expense_account.id,
5964
# "refund_account_id": cls.expense_account.id,
6065
}
61-
cls.purchase_tax = cls.env["account.tax"].create(purchase_tax_vals)
66+
cls.purchase_tax = cls.env["account.tax"].create([purchase_tax_vals])
6267
sale_tax_vals = purchase_tax_vals.copy()
6368
sale_tax_vals.update(
6469
{
@@ -67,16 +72,18 @@ def setUpClass(cls):
6772
"type_tax_use": "sale",
6873
}
6974
)
70-
cls.sale_tax = cls.env["account.tax"].create(sale_tax_vals)
75+
cls.sale_tax = cls.env["account.tax"].create([sale_tax_vals])
7176
cls.product = cls.env["product.product"].create(
72-
{
73-
"name": "Expense product",
74-
"default_code": "AII-TEST-PRODUCT",
75-
"taxes_id": [(6, 0, [cls.sale_tax.id])],
76-
"supplier_taxes_id": [(6, 0, [cls.purchase_tax.id])],
77-
"property_account_income_id": cls.income_account.id,
78-
"property_account_expense_id": cls.expense_account.id,
79-
}
77+
[
78+
{
79+
"name": "Expense product",
80+
"default_code": "AII-TEST-PRODUCT",
81+
"taxes_id": [(6, 0, [cls.sale_tax.id])],
82+
"supplier_taxes_id": [(6, 0, [cls.purchase_tax.id])],
83+
"property_account_income_id": cls.income_account.id,
84+
"property_account_expense_id": cls.expense_account.id,
85+
}
86+
]
8087
)
8188
cls.all_import_config = [
8289
{
@@ -99,51 +106,60 @@ def setUpClass(cls):
99106
# Deco Addict
100107
cls.env.ref("base.res_partner_2").customer_rank = 1
101108
cls.pur_journal1 = cls.env["account.journal"].create(
102-
{
103-
"type": "purchase",
104-
"code": "XXXP1",
105-
"name": "Test Purchase Journal 1",
106-
"sequence": 10,
107-
"company_id": cls.company.id,
108-
}
109+
[
110+
{
111+
"type": "purchase",
112+
"code": "XXXP1",
113+
"name": "Test Purchase Journal 1",
114+
"sequence": 10,
115+
"company_id": cls.company.id,
116+
}
117+
]
109118
)
110119
cls.pur_journal2 = cls.env["account.journal"].create(
111-
{
112-
"type": "purchase",
113-
"code": "XXXP2",
114-
"name": "Test Purchase Journal 2",
115-
"sequence": 100,
116-
"company_id": cls.company.id,
117-
}
120+
[
121+
{
122+
"type": "purchase",
123+
"code": "XXXP2",
124+
"name": "Test Purchase Journal 2",
125+
"sequence": 100,
126+
"company_id": cls.company.id,
127+
"default_account_id": cls.expense_account.id,
128+
}
129+
]
118130
)
119131
cls.partner_with_email = cls.env["res.partner"].create(
120-
{
121-
"is_company": True,
122-
"name": "AgroMilk",
123-
"email": "invoicing@agromilk.com",
124-
"country_id": cls.env.ref("base.fr").id,
125-
}
132+
[
133+
{
134+
"is_company": True,
135+
"name": "AgroMilk",
136+
"email": "invoicing@agromilk.com",
137+
"country_id": cls.env.ref("base.fr").id,
138+
}
139+
]
126140
)
127141
cls.partner_with_email_with_inv_config = cls.env["res.partner"].create(
128-
{
129-
"is_company": True,
130-
"name": "Anevia",
131-
"email": "invoicing@anevia.com",
132-
"country_id": cls.env.ref("base.fr").id,
133-
"invoice_import_ids": [
134-
(
135-
0,
136-
0,
137-
{
138-
"name": "Import config for Anevia",
139-
"company_id": cls.company.id,
140-
"invoice_line_method": "1line_static_product",
141-
"static_product_id": cls.product.id,
142-
"label": "Flamingo 220S",
143-
},
144-
)
145-
],
146-
}
142+
[
143+
{
144+
"is_company": True,
145+
"name": "Anevia",
146+
"email": "invoicing@anevia.com",
147+
"country_id": cls.env.ref("base.fr").id,
148+
"invoice_import_ids": [
149+
(
150+
0,
151+
0,
152+
{
153+
"name": "Import config for Anevia",
154+
"company_id": cls.company.id,
155+
"invoice_line_method": "1line_static_product",
156+
"static_product_id": cls.product.id,
157+
"label": "Flamingo 220S",
158+
},
159+
)
160+
],
161+
}
162+
]
147163
)
148164
company = cls.env.ref("base.main_company")
149165
company.update(
@@ -364,35 +380,46 @@ def test_email_gateway(self):
364380
mail_channel_noautofollow=True
365381
).message_process("account.invoice.import", self._fake_email)
366382

383+
@contextmanager
384+
def _force_message_parse(self, forced_value):
385+
@api.model
386+
def message_parse(this, message, save_original=False):
387+
return forced_value
388+
389+
MailThread = self.env["mail.thread"]
390+
MailThread._patch_method("message_parse", message_parse)
391+
yield
392+
MailThread._revert_method("message_parse")
393+
367394
def test_email_gateway_multi_comp_1_matching(self):
368395
comp = self.env["res.company"].create(
369-
{
370-
"name": "Let it fail INC",
371-
"invoice_import_email": "project-discussion@example.com",
372-
}
396+
[
397+
{
398+
"name": "Let it fail INC",
399+
"invoice_import_email": "project-discussion@example.com",
400+
}
401+
]
373402
)
374403
logger_name = "odoo.addons.account_invoice_import.wizard.account_invoice_import"
375404

376-
mock_parse = mock.patch.object(type(self.env["mail.thread"]), "message_parse")
377405
with self.assertLogs(logger_name) as watcher:
378406
# NOTE: for some reason in tests the msg is not parsed properly
379407
# and message_dict is kind of empty.
380408
# Nevertheless, it doesn't really matter
381409
# because here we want to make sure that the code works as expected
382410
# when a msg is properly parsed.
383-
with mock_parse as mocked:
384-
mocked_msg = {
385-
"to": "project-discussion@example.com",
386-
"email_from": "Nina Marton <nina@example.com>",
387-
"message_id": "<v0214040cad6a13935723@foo.com>",
388-
"references": "",
389-
"in_reply_to": "",
390-
"subject": "Happy Birthday",
391-
"recipients": "project-discussion@example.com",
392-
"body": self._fake_email,
393-
"date": "2022-05-26 10:30:00",
394-
}
395-
mocked.return_value = mocked_msg
411+
mocked_msg = {
412+
"to": "project-discussion@example.com",
413+
"email_from": "Nina Marton <nina@example.com>",
414+
"message_id": "<v0214040cad6a13935723@foo.com>",
415+
"references": "",
416+
"in_reply_to": "",
417+
"subject": "Happy Birthday",
418+
"recipients": "project-discussion@example.com",
419+
"body": self._fake_email,
420+
"date": "2022-05-26 10:30:00",
421+
}
422+
with self._force_message_parse(forced_value=mocked_msg):
396423
self.env["mail.thread"].with_context(
397424
mail_channel_noautofollow=True
398425
).message_process("account.invoice.import", self._fake_email)
@@ -408,7 +435,7 @@ def test_email_gateway_multi_comp_1_matching(self):
408435
self.assertIn(msg, "\n".join(watcher.output))
409436

410437
def test_email_gateway_multi_comp_none_matching(self):
411-
self.env["res.company"].create({"name": "Let it fail INC"})
438+
self.env["res.company"].create([{"name": "Let it fail INC"}])
412439
logger_name = "odoo.addons.account_invoice_import.wizard.account_invoice_import"
413440
with self.assertLogs(logger_name, "ERROR") as watcher:
414441
self.env["mail.thread"].with_context(

account_invoice_import/views/account_invoice_import_config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<group name="main">
2222
<field name="name" />
2323
<field name="partner_id" />
24+
<field name="company_id" invisible="1" />
2425
<field name="company_id" groups="base.group_multi_company" />
2526
<field name="active" invisible="1" />
2627
</group>

account_invoice_import/views/account_journal_dashboard.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view" />
1111
<field name="arch" type="xml">
1212
<button
13-
class="btn btn-primary o_button_upload_bill oe_kanban_action_button"
13+
name="action_create_vendor_bill"
1414
journal_type="purchase"
1515
position="attributes"
1616
>

0 commit comments

Comments
 (0)