Skip to content

Commit a0b3afc

Browse files
committed
[IMP] shopinvader_import_image: black, isort, prettier
1 parent c255041 commit a0b3afc

8 files changed

+87
-83
lines changed

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exclude: |
1010
^shopinvader_delivery_instruction/|
1111
^shopinvader_demo_app/|
1212
^shopinvader_guest_mode/|
13-
^shopinvader_import_image/|
1413
^shopinvader_lead/|
1514
^shopinvader_locomotive_algolia/|
1615
^shopinvader_locomotive_contact_company/|

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# generated from manifests external_dependencies
22
cerberus
33
locomotivecms
4+
python-magic
45
python-slugify
56
slugify
67
unidecode
8+
validators

shopinvader_import_image/data/queue_job_function_data.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<odoo noupdate="1">
2-
<record id="job_function_shopinvader_import_product_image_do_import" model="queue.job.function">
2+
<record
3+
id="job_function_shopinvader_import_product_image_do_import"
4+
model="queue.job.function"
5+
>
36
<field name="model_id" ref="model_shopinvader_import_product_image" />
47
<field name="method">do_import</field>
58
<field name="channel_id" ref="channel_shopinvader_import_image" />

shopinvader_import_image/models/import_image.py

+9-26
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ class ProductImageImportWizard(models.Model):
7878
default="default_code,tag,path",
7979
required=True,
8080
)
81-
csv_delimiter = fields.Char(
82-
string="CSV file delimiter", default=",", required=True
83-
)
81+
csv_delimiter = fields.Char(string="CSV file delimiter", default=",", required=True)
8482
source_zipfile = fields.Binary("ZIP with images", required=False)
8583
source_storage_backend_id = fields.Many2one(
8684
"storage.backend", "Storage Backend with images"
@@ -155,9 +153,7 @@ def _read_csv(self):
155153
if self.file_csv:
156154
return base64.b64decode(self.file_csv)
157155
elif self.external_csv_path:
158-
return self.source_storage_backend_id._get_bin_data(
159-
self.external_csv_path
160-
)
156+
return self.source_storage_backend_id._get_bin_data(self.external_csv_path)
161157

162158
def _get_lines(self):
163159
lines = []
@@ -167,8 +163,7 @@ def _get_lines(self):
167163

168164
if headers != self.csv_header.split(self.csv_delimiter):
169165
raise exceptions.UserError(
170-
_("Invalid CSV file headers found! Expected: %s")
171-
% self.csv_header
166+
_("Invalid CSV file headers found! Expected: %s") % self.csv_header
172167
)
173168
csv.field_size_limit(sys.maxsize)
174169

@@ -205,9 +200,7 @@ def action_import(self):
205200

206201
def do_import(self, lines=None, last_chunk=False):
207202
lines = lines or self._get_lines()
208-
report = self._do_import(
209-
lines, self.product_model, options=self._get_options()
210-
)
203+
report = self._do_import(lines, self.product_model, options=self._get_options())
211204
# Refresh report
212205
extendable_keys = [
213206
"created",
@@ -271,9 +264,7 @@ def _do_import(self, lines, product_model, options=None):
271264
if missing_tags:
272265
if options.get("create_missing_tags"):
273266
for tag_name in missing_tags:
274-
tag_by_name[tag_name] = tag_obj.create(
275-
{"name": tag_name}
276-
).id
267+
tag_by_name[tag_name] = tag_obj.create({"name": tag_name}).id
277268
else:
278269
report["missing_tags"] = sorted(missing_tags)
279270

@@ -284,9 +275,7 @@ def _do_import(self, lines, product_model, options=None):
284275
if not file_vals:
285276
report["file_not_found"].add(prod["default_code"])
286277
continue
287-
file_vals.update(
288-
{"name": file_vals["name"], "alt_name": file_vals["name"]}
289-
)
278+
file_vals.update({"name": file_vals["name"], "alt_name": file_vals["name"]})
290279
# storage_file = file_obj.create(file_vals)
291280
tag_id = tag_by_name.get(line["tag_name"])
292281

@@ -347,17 +336,11 @@ def _prepare_file_values(self, file_path, filetype="image"):
347336

348337
@api.model
349338
def _cron_cleanup_obsolete(self, days=7):
350-
from_date = fields.Datetime.now().replace(
351-
hour=23, minute=59, second=59
352-
)
339+
from_date = fields.Datetime.now().replace(hour=23, minute=59, second=59)
353340
limit_date = date_utils.subtract(from_date, days)
354-
records = self.search(
355-
[("state", "=", "done"), ("done_on", "<=", limit_date)]
356-
)
341+
records = self.search([("state", "=", "done"), ("done_on", "<=", limit_date)])
357342
records.unlink()
358-
_logger.info(
359-
"Cleanup obsolete images import. %d records found.", len(records)
360-
)
343+
_logger.info("Cleanup obsolete images import. %d records found.", len(records))
361344

362345
def _report_label_for(self, key):
363346
labels = {
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo noupdate="1">
33
<record model="ir.model.access" id="access_shopinvader_import_product_image_user">
44
<field name="name">shopinvader_import_product_image user</field>
5-
<field name="model_id" ref="model_shopinvader_import_product_image"/>
5+
<field name="model_id" ref="model_shopinvader_import_product_image" />
66
<!-- TODO: specific group from sales? -->
7-
<field name="group_id" ref="base.group_user"/>
8-
<field name="perm_read" eval="1"/>
9-
<field name="perm_create" eval="1"/>
10-
<field name="perm_write" eval="1"/>
11-
<field name="perm_unlink" eval="1"/>
7+
<field name="group_id" ref="base.group_user" />
8+
<field name="perm_read" eval="1" />
9+
<field name="perm_create" eval="1" />
10+
<field name="perm_write" eval="1" />
11+
<field name="perm_unlink" eval="1" />
1212
</record>
1313
</odoo>

shopinvader_import_image/tests/test_import_image.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
import os
77

88
import mock
9+
910
from odoo.addons.shopinvader_image.tests.common import TestShopinvaderImageCase
1011

1112

1213
class TestShopinvaderImportImageCase(TestShopinvaderImageCase):
1314
@classmethod
1415
def setUpClass(cls):
1516
super().setUpClass()
16-
cls.storage_backend = cls.env.ref(
17-
"storage_backend.default_storage_backend"
18-
)
17+
cls.storage_backend = cls.env.ref("storage_backend.default_storage_backend")
1918
cls.base_path = os.path.dirname(os.path.abspath(__file__))
2019
cls.file_csv_content = cls._get_file_content(
2120
"image_import_test.csv", base_path=cls.base_path
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,74 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<odoo>
33
<record id="product_import_image_form_view" model="ir.ui.view">
44
<field name="name">product.import.image.form</field>
55
<field name="model">shopinvader.import.product_image</field>
66
<field name="arch" type="xml">
77
<form string="Import shopinvader product images">
88
<header>
9-
<field
10-
name="state"
11-
widget="statusbar"
12-
/>
9+
<field name="state" widget="statusbar" />
1310
</header>
1411
<sheet>
15-
<div class="oe_button_box" name="active_button_box" attrs="{'invisible': [('id','=',False)]}">
16-
<button class="oe_highlight" string="Import images"
17-
name="action_import" type="object"
18-
states="new"
19-
/>
20-
<button class="oe_highlight" string="Import images again"
21-
name="action_import" type="object"
22-
states="done"
23-
/>
12+
<div
13+
class="oe_button_box"
14+
name="active_button_box"
15+
attrs="{'invisible': [('id','=',False)]}"
16+
>
17+
<button
18+
class="oe_highlight"
19+
string="Import images"
20+
name="action_import"
21+
type="object"
22+
states="new"
23+
/>
24+
<button
25+
class="oe_highlight"
26+
string="Import images again"
27+
name="action_import"
28+
type="object"
29+
states="done"
30+
/>
2431
</div>
2532
<field name="id" invisible="1" />
2633
<group name="main">
27-
<field name="storage_backend_id"/>
28-
<field name="product_model"/>
29-
<field name="source_type"/>
30-
<field name="file_csv" filename="filename"
31-
attrs="{
34+
<field name="storage_backend_id" />
35+
<field name="product_model" />
36+
<field name="source_type" />
37+
<field
38+
name="file_csv"
39+
filename="filename"
40+
attrs="{
3241
'required': [('source_type', '!=', 'external_storage')],
3342
'invisible': [('source_type', '=', 'external_storage')]
34-
}"/>
35-
<field name="source_zipfile" filename="filename"
36-
attrs="{
43+
}"
44+
/>
45+
<field
46+
name="source_zipfile"
47+
filename="filename"
48+
attrs="{
3749
'required': [('source_type', '=', 'zip_file')],
3850
'invisible': [('source_type', '!=', 'zip_file')]
39-
}"/>
40-
<field name="source_storage_backend_id"
41-
attrs="{
51+
}"
52+
/>
53+
<field
54+
name="source_storage_backend_id"
55+
attrs="{
4256
'required': [('source_type', '=', 'external_storage')],
4357
'invisible': [('source_type', '!=', 'external_storage')],
44-
}"/>
45-
<field name="external_csv_path"
46-
attrs="{
58+
}"
59+
/>
60+
<field
61+
name="external_csv_path"
62+
attrs="{
4763
'required': [('source_type', '=', 'external_storage')],
4864
'invisible': [('source_type', '!=', 'external_storage')],
49-
}"/>
50-
<field name="csv_header"/>
51-
<field name="csv_delimiter"/>
52-
<field name="overwrite"/>
53-
<field name="create_missing_tags"/>
54-
<field name="chunk_size"/>
65+
}"
66+
/>
67+
<field name="csv_header" />
68+
<field name="csv_delimiter" />
69+
<field name="overwrite" />
70+
<field name="create_missing_tags" />
71+
<field name="chunk_size" />
5572
</group>
5673
<separator string="Report" />
5774
<field name="report_html" nolabel="1" />
@@ -66,15 +83,16 @@
6683
<field name="name">product.import.image.tree</field>
6784
<field name="model">shopinvader.import.product_image</field>
6885
<field name="arch" type="xml">
69-
<tree string="Import shopinvader product images"
86+
<tree
87+
string="Import shopinvader product images"
7088
decoration-warning="state == 'scheduled'"
7189
decoration-success="state == 'done'"
7290
>
73-
<field name="storage_backend_id"/>
74-
<field name="product_model"/>
75-
<field name="source_type"/>
76-
<field name="state"/>
77-
<field name="done_on"/>
91+
<field name="storage_backend_id" />
92+
<field name="product_model" />
93+
<field name="source_type" />
94+
<field name="state" />
95+
<field name="done_on" />
7896
</tree>
7997
</field>
8098
</record>
@@ -93,13 +111,13 @@
93111
parent="sale.product_menu_catalog"
94112
action="import_image_action"
95113
sequence="999"
96-
/>
114+
/>
97115

98116
<record model="ir.ui.menu" id="menu_backend_shopinvader_image_import">
99117
<field name="name">Import product images</field>
100-
<field name="parent_id" ref="shopinvader.menu_shopinvader_root"/>
101-
<field name="action" ref="import_image_action"/>
102-
<field name="sequence" eval="30"/>
118+
<field name="parent_id" ref="shopinvader.menu_shopinvader_root" />
119+
<field name="action" ref="import_image_action" />
120+
<field name="sequence" eval="30" />
103121
</record>
104122

105123
</odoo>

shopinvader_import_image/views/report_html.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<odoo>
33
<template id="report_html">
44
<div class="report-html mb16">

0 commit comments

Comments
 (0)