Skip to content

Commit 0812682

Browse files
[16.0][MIG-REF] fs_import_image_advanced
- Refactor from storage_import_image_advanced - Change to user fs_storage and fs_product_multi_image as dependencies - Fix test to use properly test class dependency
1 parent 5fa49db commit 0812682

28 files changed

+73
-58
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,35 @@ Import Storage product image
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:1d706ff34e4744344df7869c85d93483d4df078dd65b142064cbf75bc4f0e4eb
10+
!! source digest: sha256:6b8c3532008323c4855704ee06cb4519b25bf2ff635698948a373b218cc331cf
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
13-
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
1414
:target: https://odoo-community.org/page/development-status
15-
:alt: Beta
15+
:alt: Alpha
1616
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
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%2Fstorage-lightgray.png?logo=github
20-
:target: https://github.com/OCA/storage/tree/15.0/storage_import_image_advanced
20+
:target: https://github.com/OCA/storage/tree/16.0/fs_import_image_advanced
2121
:alt: OCA/storage
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/storage-15-0/storage-15-0-storage_import_image_advanced
23+
:target: https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_import_image_advanced
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/storage&target_branch=15.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=16.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

3131
Import product image from a CVS file from URLs or ZIP file',
3232
Idea based on an idea of the 'image_product_import' from Cybrosys Techno Solutions
3333

34+
.. IMPORTANT::
35+
This is an alpha version, the data model and design can change at any time without warning.
36+
Only for development or testing purpose, do not use in production.
37+
`More details on development status <https://odoo-community.org/page/development-status>`_
38+
3439
**Table of contents**
3540

3641
.. contents::
@@ -42,7 +47,7 @@ Bug Tracker
4247
Bugs are tracked on `GitHub Issues <https://github.com/OCA/storage/issues>`_.
4348
In case of trouble, please check there if your issue has already been reported.
4449
If you spotted it first, help us to smash it by providing a detailed and welcomed
45-
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20storage_import_image_advanced%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
50+
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_import_image_advanced%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
4651

4752
Do not contact contributors directly about support or help with technical issues.
4853

@@ -76,6 +81,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
7681
mission is to support the collaborative development of Odoo features and
7782
promote its widespread use.
7883

79-
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/15.0/storage_import_image_advanced>`_ project on GitHub.
84+
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/16.0/fs_import_image_advanced>`_ project on GitHub.
8085

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

storage_import_image_advanced/__manifest__.py renamed to fs_import_image_advanced/__manifest__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
77
{
88
"name": "Import Storage product image",
9-
"version": "15.0.1.0.0",
9+
"version": "16.0.1.0.0",
1010
"summary": "Import product images using CSV",
1111
"author": "Akretion, Camptocamp, Odoo Community Association (OCA)",
1212
"company": "Akretion",
1313
"maintainer": "Akretion",
1414
"website": "https://github.com/OCA/storage",
1515
"category": "Product",
16-
"depends": ["storage_image_product", "queue_job"],
16+
"development_status": "Alpha",
17+
"depends": ["fs_product_multi_image", "sale", "queue_job"],
1718
"external_dependencies": {
1819
"python": ["python-magic", "validators"],
1920
"deb": ["libmagic1"],
File renamed without changes.

storage_import_image_advanced/data/queue_job_channel_data.xml renamed to fs_import_image_advanced/data/queue_job_channel_data.xml

File renamed without changes.

storage_import_image_advanced/data/queue_job_function_data.xml renamed to fs_import_image_advanced/data/queue_job_function_data.xml

File renamed without changes.

storage_import_image_advanced/i18n/shopinvader_import_image.pot renamed to fs_import_image_advanced/i18n/shopinvader_import_image.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ msgid "Source type"
235235
msgstr ""
236236

237237
#. module: shopinvader_import_image
238-
#: model:ir.model.fields,field_description:shopinvader_import_image.field_shopinvader_import_product_image__storage_backend_id
238+
#: model:ir.model.fields,field_description:shopinvader_import_image.field_shopinvader_import_product_image__fs_storage_id
239239
msgid "Storage Backend"
240240
msgstr ""
241241

242242
#. module: shopinvader_import_image
243-
#: model:ir.model.fields,field_description:shopinvader_import_image.field_shopinvader_import_product_image__source_storage_backend_id
243+
#: model:ir.model.fields,field_description:shopinvader_import_image.field_shopinvader_import_product_image__source_fs_storage_id
244244
msgid "Storage Backend with images"
245245
msgstr ""
246246

storage_import_image_advanced/i18n/storage_import_image_advanced.pot renamed to fs_import_image_advanced/i18n/storage_import_image_advanced.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ msgid "Source Type"
272272
msgstr ""
273273

274274
#. module: storage_import_image_advanced
275-
#: model:ir.model.fields,field_description:storage_import_image_advanced.field_storage_import_product_image__storage_backend_id
275+
#: model:ir.model.fields,field_description:storage_import_image_advanced.field_storage_import_product_image__fs_storage_id
276276
msgid "Storage Backend"
277277
msgstr ""
278278

279279
#. module: storage_import_image_advanced
280-
#: model:ir.model.fields,field_description:storage_import_image_advanced.field_storage_import_product_image__source_storage_backend_id
280+
#: model:ir.model.fields,field_description:storage_import_image_advanced.field_storage_import_product_image__source_fs_storage_id
281281
msgid "Storage Backend with images"
282282
msgstr ""
283283

File renamed without changes.

storage_import_image_advanced/models/import_image.py renamed to fs_import_image_advanced/models/import_image.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def _default_csv_header(self):
5757
flds = [product_identifier, "tag", "path"]
5858
return ",".join(flds)
5959

60-
storage_backend_id = fields.Many2one(
61-
"storage.backend", "Storage Backend", required=True
62-
)
60+
fs_storage_id = fields.Many2one("fs.storage", "FS Storage", required=True)
6361
product_model = fields.Selection(
6462
[
6563
("product.template", "Product template"),
@@ -104,9 +102,7 @@ def _default_csv_header(self):
104102
)
105103
csv_delimiter = fields.Char(string="CSV file delimiter", default=",", required=True)
106104
source_zipfile = fields.Binary("ZIP with images", required=False)
107-
source_storage_backend_id = fields.Many2one(
108-
"storage.backend", "Storage Backend with images"
109-
)
105+
source_fs_storage_id = fields.Many2one("fs.storage", "FS Storage with images")
110106
external_csv_path = fields.Char(
111107
string="Path to CSV file",
112108
help="Relative path of the CSV file located in the external storage",
@@ -133,7 +129,7 @@ def _default_csv_header(self):
133129
@api.depends("report")
134130
def _compute_report_html(self):
135131
# TODO: add tests
136-
tmpl = self.env.ref("storage_import_image_advanced.report_html")
132+
tmpl = self.env.ref("fs_import_image_advanced.report_html")
137133
for record in self:
138134
if not record.report:
139135
record.report_html = ""
@@ -154,7 +150,7 @@ def _get_base64(self, file_path):
154150

155151
def _read_from_url(self, file_path):
156152
if validators.url(file_path):
157-
return urlopen(file_path).read()
153+
return urlopen(file_path, timeout=120).read()
158154
return None
159155

160156
def _read_from_zip_file(self, file_path):
@@ -170,15 +166,15 @@ def _read_from_zip_file(self, file_path):
170166
return None
171167

172168
def _read_from_external_storage(self, file_path):
173-
if not self.source_storage_backend_id:
169+
if not self.source_fs_storage_id:
174170
raise exceptions.UserError(_("No storage backend provided!"))
175-
return self.source_storage_backend_id._get_bin_data(file_path)
171+
return self.source_fs_storage_id._get_filesystem().open(file_path)
176172

177173
def _read_csv(self):
178174
if self.file_csv:
179175
return base64.b64decode(self.file_csv)
180176
elif self.external_csv_path:
181-
return self.source_storage_backend_id._get_bin_data(self.external_csv_path)
177+
return self.source_fs_storage_id._get_bin_data(self.external_csv_path)
182178

183179
def _get_lines(self):
184180
lines = []
@@ -258,8 +254,8 @@ def _assign_product_tmpl_attr_values(self, product):
258254

259255
def _do_import(self, lines, product_model, options=None):
260256
tag_obj = self.env["image.tag"]
261-
image_obj = self.env["storage.image"]
262-
relation_obj = self.env["product.image.relation"]
257+
image_obj = self.env["fs.image"]
258+
relation_obj = self.env["fs.product.image"]
263259
product_identifier_field = self._get_product_identifier_field()
264260
report = {
265261
"created": set(),
@@ -305,8 +301,6 @@ def _do_import(self, lines, product_model, options=None):
305301
if not file_vals:
306302
report["file_not_found"].add(prod[product_identifier_field])
307303
continue
308-
file_vals.update({"name": file_vals["name"], "alt_name": file_vals["name"]})
309-
# storage_file = file_obj.create(file_vals)
310304
tag_id = tag_by_name.get(line["tag_name"])
311305

312306
if product_model == "product.template":
@@ -344,7 +338,6 @@ def _do_import(self, lines, product_model, options=None):
344338
)
345339
]
346340
relation_obj.create(img_relation_values)
347-
image._compute_main_thumbs()
348341
report["created"].add(prod[product_identifier_field])
349342
report["created"] = sorted(report["created"])
350343
report["file_not_found"] = sorted(report["file_not_found"])
@@ -356,11 +349,10 @@ def _prepare_file_values(self, file_path, filetype="image"):
356349
if not file_data:
357350
return {}
358351
vals = {
359-
"data": file_data["b64"],
360-
"name": name,
361-
"file_type": filetype,
362-
"mimetype": file_data["mimetype"],
363-
"backend_id": self.storage_backend_id.id,
352+
"image": {
353+
"filename": name,
354+
"content": file_data["b64"],
355+
},
364356
}
365357
return vals
366358

0 commit comments

Comments
 (0)