Skip to content

Commit 41bad05

Browse files
[MIG] document_quick_access_folder_auto_classification: Migration to 18.0
1 parent 8243a38 commit 41bad05

File tree

8 files changed

+34
-36
lines changed

8 files changed

+34
-36
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from . import components
21
from . import models
32
from . import wizards

document_quick_access_folder_auto_classification/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"name": "Document Quick Access Folder Auto Classification",
66
"summary": """
77
Auto classification of Documents after reading a QR""",
8-
"version": "16.0.1.0.1",
8+
"version": "18.0.1.0.0",
99
"license": "AGPL-3",
1010
"author": "Creu Blanca,Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/server-ux",
12-
"depends": ["document_quick_access", "edi_oca"],
12+
"depends": ["document_quick_access", "edi_component_oca"],
1313
"external_dependencies": {
1414
"deb": ["libzbar0", "poppler-utils"],
1515
"python": ["pyzbar", "pdf2image"],

document_quick_access_folder_auto_classification/components/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

document_quick_access_folder_auto_classification/data/edi_data.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<field name="backend_type_id" ref="backend_type" />
1111
<field name="direction">input</field>
1212
<field name="exchange_filename_pattern" />
13+
<field name="process_model_id" ref="model_document_quick_access_handler" />
1314
</record>
1415
<record id="edi_backend" model="edi.backend">
1516
<field name="name">Document quick access auto classification</field>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import document_quick_access_rule
2+
from . import document_quick_access_handler
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
# Copyright 2021 Creu Blanca
2-
# @author: Enric Tobella
3-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4-
51
import base64
62
import logging
73
import traceback
84
from io import StringIO
95

10-
from odoo import _
6+
from odoo import _, models
117
from odoo.exceptions import UserError
128

13-
from odoo.addons.component.core import Component
14-
159
_logger = logging.getLogger(__name__)
1610

1711
try:
@@ -29,30 +23,32 @@
2923
_logger.warning(err)
3024

3125

32-
class EdiDocumentQuickAccessProcess(Component):
33-
_name = "edi.input.process.document.quick.access"
34-
_usage = "input.process"
35-
_backend_type = "document_quick_access"
36-
_exchange_type = "document_quick_access"
37-
_inherit = "edi.component.input.mixin"
26+
class EdiDocumentQuickAccessHandler(models.AbstractModel):
27+
_name = "document.quick.access.handler"
28+
_inherit = [
29+
"edi.oca.handler.process",
30+
]
31+
_description = "Component Handler for Document Quick Access"
3832

39-
def process(self):
40-
data = self.exchange_record.exchange_file
33+
def process(self, exchange_record):
34+
data = exchange_record.exchange_file
4135
records = self._search_document_pdf(data)
4236
for record in records:
43-
self.env["ir.attachment"].create(self._get_attachment_vals(record))
37+
self.env["ir.attachment"].create(
38+
self._get_attachment_vals(record, exchange_record)
39+
)
4440
if records:
4541
record = records[0]
46-
self.exchange_record.write({"res_id": record.id, "model": record._name})
42+
exchange_record.write({"res_id": record.id, "model": record._name})
4743
elif self.env.context.get("document_quick_access_reject_file"):
4844
return
4945
else:
5046
raise UserError(_("No file found"))
5147

52-
def _get_attachment_vals(self, record):
48+
def _get_attachment_vals(self, record, exchange_record):
5349
return {
54-
"name": self.exchange_record.exchange_filename,
55-
"datas": self.exchange_record.exchange_file,
50+
"name": exchange_record.exchange_filename,
51+
"datas": exchange_record.exchange_file,
5652
"res_id": record.id,
5753
"res_model": record._name,
5854
}

document_quick_access_folder_auto_classification/tests/test_document_quick_access_auto_classification.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from odoo import tools
88
from odoo.tools import mute_logger
99

10-
from odoo.addons.component.tests.common import TransactionComponentRegistryCase
10+
from odoo.addons.edi_component_oca.tests.common import (
11+
EDIBackendCommonComponentRegistryTestCase,
12+
)
1113

1214

1315
class Encoded:
@@ -17,7 +19,7 @@ def __init__(self, data):
1719
self.data = data
1820

1921

20-
class TestDocumentQuickAccessClassification(TransactionComponentRegistryCase):
22+
class TestDocumentQuickAccessClassification(EDIBackendCommonComponentRegistryTestCase):
2123
@classmethod
2224
def setUpClass(cls):
2325
super().setUpClass()
@@ -77,7 +79,7 @@ def test_ok_pdf(self, partners=False):
7779
]
7880
with patch(
7981
"odoo.addons.document_quick_access_folder_auto_classification."
80-
"components.document_quick_access_process.decode"
82+
"models.document_quick_access_handler.decode"
8183
) as ptch:
8284
ptch.return_value = code
8385
self.backend.create_record(
@@ -164,7 +166,7 @@ def test_failure(self):
164166
with self.assertRaises(TypeError):
165167
with patch(
166168
"odoo.addons.document_quick_access_folder_auto_classification."
167-
"components.document_quick_access_process.decode"
169+
"models.document_quick_access_handler.decode"
168170
) as ptch:
169171
ptch.return_value = 1
170172
self.backend.create_record(

document_quick_access_folder_auto_classification/views/edi_exchange_record.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
type="action"
1717
class="primary"
1818
string="Assign"
19-
attrs="{'invisible': [('edi_exchange_state', '!=', 'input_processed_error')]}"
20-
context="{'default_exchange_record_id': active_id}"
19+
invisible="edi_exchange_state != 'input_processed_error'"
20+
context="{'default_exchange_record_id': id}"
2121
/>
2222
<button
2323
name="action_exchange_process"
2424
type="object"
2525
string="Reject"
26-
attrs="{'invisible': [('edi_exchange_state', '!=', 'input_processed_error')]}"
26+
invisible="edi_exchange_state != 'input_processed_error'"
2727
context="{'document_quick_access_reject_file': True}"
2828
/>
2929
<button
3030
name="action_open_related_record"
3131
type="object"
3232
string="Related record"
33-
attrs="{'invisible': ['|', ('edi_exchange_state', '!=', 'input_processed'), ('model', '=', False)]}"
33+
invisible="edi_exchange_state != 'input_processed' or model == False"
3434
/>
3535
<field
3636
name="edi_exchange_state"
@@ -87,25 +87,25 @@
8787
<field name="model">edi.exchange.record</field>
8888
<field name="priority">99</field>
8989
<field name="arch" type="xml">
90-
<tree create="false" delete="false">
90+
<list create="false" delete="false">
9191
<field name="exchange_filename" />
9292
<field name="edi_exchange_state" />
9393
<field name="create_date" />
94-
</tree>
94+
</list>
9595
</field>
9696
</record>
9797

9898
<record model="ir.actions.act_window" id="document_quick_access_missing_act_window">
9999
<field name="name">Document Quick Access Missing</field>
100100
<field name="res_model">edi.exchange.record</field>
101-
<field name="view_mode">tree,form</field>
101+
<field name="view_mode">list,form</field>
102102
<field name="domain">[("type_id.code", "=", "document_quick_access")]</field>
103103
<field name="context">{'search_default_pending': 1}</field>
104104
<field name="search_view_id" ref="document_quick_access_missing_search_view" />
105105
<field
106106
name="view_ids"
107107
eval="[(5, 0, 0),
108-
(0, 0, {'view_mode': 'tree', 'view_id': ref('document_quick_access_missing_tree_view')}),
108+
(0, 0, {'view_mode': 'list', 'view_id': ref('document_quick_access_missing_tree_view')}),
109109
(0, 0, {'view_mode': 'form', 'view_id': ref('document_quick_access_missing_form_view')})]"
110110
/>
111111
</record>

0 commit comments

Comments
 (0)