Skip to content

Commit b4e2881

Browse files
committed
[MIG] account_invoice_import_invoice2data: Migration to 16.0
1 parent fafdcf6 commit b4e2881

File tree

10 files changed

+79
-53
lines changed

10 files changed

+79
-53
lines changed

account_invoice_import_invoice2data/README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Account Invoice Import Invoice2data
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_invoice2data
20+
:target: https://github.com/OCA/edi/tree/16.0/account_invoice_import_invoice2data
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_invoice2data
23+
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import_invoice2data
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|
@@ -245,7 +245,7 @@ Bug Tracker
245245
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
246246
In case of trouble, please check there if your issue has already been reported.
247247
If you spotted it first, help us to smash it by providing a detailed and welcomed
248-
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import_invoice2data%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
248+
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import_invoice2data%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
249249

250250
Do not contact contributors directly about support or help with technical issues.
251251

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

287287
|maintainer-alexis-via| |maintainer-bosd|
288288

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

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

account_invoice_import_invoice2data/__manifest__.py

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

55
{
66
"name": "Account Invoice Import Invoice2data",
7-
"version": "14.0.2.4.0",
7+
"version": "16.0.1.0.0",
88
"category": "Accounting/Accounting",
99
"license": "AGPL-3",
1010
"summary": "Import supplier invoices using the invoice2data lib",

account_invoice_import_invoice2data/demo/demo_data.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<field name="zip">75008</field>
1919
<field name="city">Paris</field>
2020
<field name="country_id" ref="base.fr" />
21-
<field name="website">http://www.free.fr</field>
21+
<field name="website">https://www.free.fr</field>
2222
<field name="vat">FR60421938861</field>
2323
</record>
2424

account_invoice_import_invoice2data/static/description/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">Account Invoice Import Invoice2data</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:c7d1d2a38227a9bf81bc6132091b5285a4afe0b1280bea7541ebab212f57f16a
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_invoice2data"><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_invoice2data"><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_invoice2data"><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_invoice2data"><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 is an extension of the module <em>account_invoice_import</em>: it adds support for regular PDF invoices i.e. PDF invoice that don’t have an embedded XML file. It uses the <a class="reference external" href="https://github.com/invoice-x/invoice2data">invoice2data library</a> which takes care of extracting the text of the PDF invoice, find an existing invoice template and execute the invoice template to extract the useful information from the invoice.</p>
374374
<p>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>
375375
<p>More information for creating the templates can be found in <a class="reference external" href="https://github.com/invoice-x/invoice2data/blob/master/TUTORIAL.md">tutorial of the invoice2data library</a>. The templates have to be created manually. An graphical template creator for odoo is a work in progress.</p>
@@ -570,7 +570,7 @@ <h1><a class="toc-backref" href="#toc-entry-7">Bug Tracker</a></h1>
570570
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi/issues">GitHub Issues</a>.
571571
In case of trouble, please check there if your issue has already been reported.
572572
If you spotted it first, help us to smash it by providing a detailed and welcomed
573-
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import_invoice2data%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
573+
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import_invoice2data%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
574574
<p>Do not contact contributors directly about support or help with technical issues.</p>
575575
</div>
576576
<div class="section" id="credits">
@@ -598,7 +598,7 @@ <h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
598598
promote its widespread use.</p>
599599
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
600600
<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> <a class="reference external image-reference" href="https://github.com/bosd"><img alt="bosd" src="https://github.com/bosd.png?size=40px" /></a></p>
601-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import_invoice2data">OCA/edi</a> project on GitHub.</p>
601+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import_invoice2data">OCA/edi</a> project on GitHub.</p>
602602
<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>
603603
</div>
604604
</div>

account_invoice_import_invoice2data/tests/test_invoice_import.py

+47-38
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
import base64
6-
import logging
5+
from base64 import b64encode
6+
from logging import getLogger
77
from unittest import mock
88

99
from odoo import fields
10-
from odoo.tests.common import SavepointCase
10+
from odoo.tests.common import TransactionCase
1111
from odoo.tools import file_open, float_compare
1212

1313
# TODO v16: use
@@ -21,19 +21,21 @@
2121
}
2222

2323

24-
class TestInvoiceImport(SavepointCase):
24+
class TestInvoiceImport(TransactionCase):
2525
@classmethod
2626
def setUpClass(cls):
2727
super().setUpClass()
2828
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
2929
frtax = cls.env["account.tax"].create(
30-
{
31-
"name": "French VAT purchase 20.0%",
32-
"description": "FR-VAT-buy-20.0",
33-
"amount": 20,
34-
"amount_type": "percent",
35-
"type_tax_use": "purchase",
36-
}
30+
[
31+
{
32+
"name": "French VAT purchase 20.0%",
33+
"description": "FR-VAT-buy-20.0",
34+
"amount": 20,
35+
"amount_type": "percent",
36+
"type_tax_use": "purchase",
37+
}
38+
]
3739
)
3840
# Set this tax on Internet access product
3941
internet_product = cls.env.ref(
@@ -44,25 +46,27 @@ def setUpClass(cls):
4446
def test_have_invoice2data_unavailable(self):
4547
with mock.patch.dict("sys.modules", {"invoice2data": None}):
4648
with self.assertLogs("", level="DEBUG") as cm:
47-
logging.getLogger("").debug("Cannot import invoice2data")
49+
getLogger("").debug("Cannot import invoice2data")
4850
self.assertEqual(cm.output, ["DEBUG:root:Cannot import invoice2data"])
4951

5052
def test_have_tesseract_unavailable(self):
5153
with mock.patch.dict("sys.modules", {"tesseract": None}):
5254
with self.assertLogs("", level="DEBUG") as cm:
53-
logging.getLogger("").debug("Cannot import tesseract")
55+
getLogger("").debug("Cannot import tesseract")
5456
self.assertEqual(cm.output, ["DEBUG:root:Cannot import tesseract"])
5557

5658
def test_import_free_invoice(self):
5759
filename = "invoice_free_fiber_201507.pdf"
5860
f = file_open("account_invoice_import_invoice2data/tests/pdf/" + filename, "rb")
5961
pdf_file = f.read()
60-
pdf_file_b64 = base64.b64encode(pdf_file)
62+
pdf_file_b64 = b64encode(pdf_file)
6163
wiz = self.env["account.invoice.import"].create(
62-
{
63-
"invoice_file": pdf_file_b64,
64-
"invoice_filename": filename,
65-
}
64+
[
65+
{
66+
"invoice_file": pdf_file_b64,
67+
"invoice_filename": filename,
68+
}
69+
]
6670
)
6771
f.close()
6872
wiz.import_invoice()
@@ -107,10 +111,12 @@ def test_import_free_invoice(self):
107111

108112
# New import with update of an existing draft invoice
109113
wiz2 = self.env["account.invoice.import"].create(
110-
{
111-
"invoice_file": pdf_file_b64,
112-
"invoice_filename": "invoice_free_fiber_201507.pdf",
113-
}
114+
[
115+
{
116+
"invoice_file": pdf_file_b64,
117+
"invoice_filename": "invoice_free_fiber_201507.pdf",
118+
}
119+
]
114120
)
115121
action = wiz2.import_invoice()
116122
self.assertEqual(action["res_model"], "account.invoice.import")
@@ -130,21 +136,24 @@ def test_import_free_invoice(self):
130136
def test_import_azure_interior_invoice(self):
131137
"""Function for testing almost all supported fields"""
132138
filename = "AzureInterior.pdf"
133-
invoice_file = file_open(
139+
140+
with file_open(
134141
"account_invoice_import_invoice2data/tests/pdf/" + filename, "rb"
135-
)
136-
pdf_file = invoice_file.read()
137-
pdf_file_b64 = base64.b64encode(pdf_file)
138-
wiz = self.env["account.invoice.import"].create(
139-
{
140-
"invoice_file": pdf_file_b64,
141-
"invoice_filename": filename,
142-
}
143-
)
144-
invoice_file.close()
142+
) as invoice_file:
143+
pdf_file = invoice_file.read()
144+
pdf_file_b64 = b64encode(pdf_file)
145+
wiz = self.env["account.invoice.import"].create(
146+
[
147+
{
148+
"invoice_file": pdf_file_b64,
149+
"invoice_filename": filename,
150+
}
151+
]
152+
)
153+
145154
wiz.import_invoice()
146155
# create_invoice_action_button
147-
wiz.create_invoice_action(origin="BOSD Import Vendor Bill wizard")
156+
# wiz.create_invoice_action(origin="BOSD Import Vendor Bill wizard")
148157
# Check result of invoice creation
149158
invoices = self.env["account.move"].search(
150159
[
@@ -167,7 +176,7 @@ def test_import_azure_interior_invoice(self):
167176

168177
self.assertEqual(
169178
inv.narration,
170-
"Due to global inflation our payment term has changed to 15 days.",
179+
"<p>Due to global inflation our payment term has changed to 15 days.</p>",
171180
)
172181

173182
# Following tests are disabled. Not yet implemented in account_invoice_import
@@ -179,7 +188,7 @@ def test_import_azure_interior_invoice(self):
179188
self.assertEqual(iline.name, "--- Non Food ---")
180189
self.assertEqual(iline.display_type, "line_section")
181190
iline = inv.invoice_line_ids[1]
182-
self.assertEqual(iline.name, "Beeswax XL\nAcme beeswax")
191+
self.assertEqual(iline.name, "[17589684] Beeswax XL")
183192
self.assertEqual(
184193
iline.product_id,
185194
self.env.ref("account_invoice_import_invoice2data.product_beeswax_xl"),
@@ -188,7 +197,7 @@ def test_import_azure_interior_invoice(self):
188197
self.assertEqual(float_compare(iline.price_unit, 42.00, precision_digits=2), 0)
189198

190199
iline = inv.invoice_line_ids[2]
191-
self.assertEqual(iline.name, "Office Chair")
200+
self.assertEqual(iline.name, "[FURN_7777] Office Chair")
192201
self.assertEqual(
193202
iline.product_id,
194203
self.env.ref("product.product_delivery_01"),
@@ -214,7 +223,7 @@ def test_import_azure_interior_invoice(self):
214223
)
215224
self.assertEqual(iline.display_type, "line_note")
216225
iline = inv.invoice_line_ids[6]
217-
self.assertEqual(iline.name, "Luxury Truffles")
226+
self.assertEqual(iline.name, "[LUX_TRF] Luxury Truffles")
218227
self.assertEqual(
219228
iline.product_id,
220229
self.env.ref("account_invoice_import_invoice2data.luxury_truffles"),

account_invoice_import_invoice2data/wizard/account_invoice_import.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def fallback_parse_pdf_invoice(self, file_data):
4040

4141
@api.model
4242
def parse_invoice2data_taxes(self, line):
43+
amount = 0.0
44+
amount_type = False
4345
taxes = []
4446
type_code = "VAT"
4547
price_include = False
@@ -69,10 +71,12 @@ def parse_invoice2data_taxes(self, line):
6971
)
7072
return taxes
7173

72-
def _clean_string(self, string):
74+
@staticmethod
75+
def _clean_string(string):
7376
return re.sub(r"\W+", "", string)
7477

75-
def _clean_digits(self, string):
78+
@staticmethod
79+
def _clean_digits(string):
7680
return re.sub(r"\D+", "", string)
7781

7882
@api.model
@@ -98,7 +102,9 @@ def invoice2data_parse_invoice(self, file_data):
98102
invoice2data_res = extract_data(fileobj.name, templates=templates)
99103
except Exception as e:
100104
fileobj.close()
101-
raise UserError(_("PDF Invoice parsing failed. Error message: %s") % e)
105+
raise UserError(
106+
_("PDF Invoice parsing failed. Error message: %s") % e
107+
) from None
102108
if not invoice2data_res:
103109
if not shutil.which("tesseract"):
104110
logger.warning(
@@ -116,7 +122,9 @@ def invoice2data_parse_invoice(self, file_data):
116122
)
117123
except Exception as e:
118124
fileobj.close()
119-
raise UserError(_("PDF Invoice parsing failed. Error message: %s") % e)
125+
raise UserError(
126+
_("PDF Invoice parsing failed. Error message: %s") % e
127+
) from None
120128
if not invoice2data_res:
121129
fileobj.close()
122130
return False

account_invoice_import_invoice2data/wizard/account_invoice_import_view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<li><b>regular PDF</b> file without any embedded XML file via the <a
1717
href="https://github.com/invoice-x/invoice2data/"
1818
target="_blank"
19-
>invoice2data</a> library (reads the text of the PDF and get the information). It will work only if the invoice2data library has a template for the invoices of that supplier.</li>
19+
>invoice2data</a> library (reads the text of the PDF and get the information). It will work only if the invoice2data library has a template for the invoices for that supplier.</li>
2020
</ul>
2121
</field>
2222
</record>

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# generated from manifests external_dependencies
2+
dateparser
23
dotty-dict
34
factur-x<=3.1
5+
invoice2data
46
phonenumbers
57
pydifact
68
pytz
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../account_invoice_import_invoice2data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)