Skip to content

Commit e1052c8

Browse files
author
davidpalanca
committed
[FIX] connetor_prestashop: valid_ean and detailed_type when create products
1 parent 036340f commit e1052c8

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

connector_prestashop/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Contributors
175175
* Marc Poch <[email protected]>
176176
* JesusVMayor <[email protected]>
177177
* Hai Lang <[email protected]>
178+
* David Palanca <[email protected]>
178179

179180
* `Greenice <https://www.greenice.com>`_:
180181

connector_prestashop/models/product_product/importer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,20 @@ def default_code(self, record):
298298
@mapping
299299
def barcode(self, record):
300300
barcode = record.get("barcode") or record.get("ean13")
301-
check_ean = self.env["barcode.nomenclature"].check_ean
301+
barcode_nomenclature_model = self.env["barcode.nomenclature"]
302+
303+
def is_valid_ean(barcode):
304+
"""Validates if a barcode is a valid EAN."""
305+
return barcode_nomenclature_model.check_encoding(barcode, "ean13")
306+
302307
if barcode in ["", "0"]:
303308
backend_adapter = self.component(
304309
usage="backend.adapter", model_name="prestashop.product.template"
305310
)
306311
template = backend_adapter.read(record["id_product"])
307312
barcode = template.get("barcode") or template.get("ean13")
308-
if barcode and barcode != "0" and check_ean(barcode):
313+
314+
if barcode and barcode != "0" and is_valid_ean(barcode):
309315
return {"barcode": barcode}
310316
return {}
311317

connector_prestashop/models/product_template/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ def update_prestashop_quantities(self):
4949
).recompute_prestashop_qty()
5050
return True
5151

52+
@api.model
53+
def create(self, vals):
54+
if "type" in vals:
55+
if vals["type"] == "product":
56+
vals["detailed_type"] = "product"
57+
elif vals["type"] == "consu":
58+
vals["detailed_type"] = "consu"
59+
elif vals["type"] == "service":
60+
vals["detailed_type"] = "service"
61+
return super(ProductTemplate, self).create(vals)
62+
5263

5364
class ProductQtyMixin(models.AbstractModel):
5465
_name = "prestashop.product.qty.mixin"

connector_prestashop/models/product_template/importer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,17 @@ def company_id(self, record):
338338
def barcode(self, record):
339339
if self.has_combinations(record):
340340
return {}
341+
341342
barcode = record.get("barcode") or record.get("ean13")
342343
if barcode in ["", "0"]:
343344
return {}
344-
if self.env["barcode.nomenclature"].check_ean(barcode):
345+
346+
barcode_nomenclature = self.env["barcode.nomenclature"]
347+
if barcode_nomenclature.check_encoding(
348+
barcode, "ean13"
349+
) or barcode_nomenclature.check_encoding(barcode, "ean8"):
345350
return {"barcode": barcode}
351+
346352
return {}
347353

348354
def _get_tax_ids(self, record):

connector_prestashop/static/description/index.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -527,6 +527,7 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
527527
<li>Marc Poch &lt;<a class="reference external" href="mailto:mpoch&#64;planetatic.com">mpoch&#64;planetatic.com</a>&gt;</li>
528528
<li>JesusVMayor &lt;<a class="reference external" href="mailto:jesus&#64;comunitea.com">jesus&#64;comunitea.com</a>&gt;</li>
529529
<li>Hai Lang &lt;<a class="reference external" href="mailto:hailn&#64;trobz.com">hailn&#64;trobz.com</a>&gt;</li>
530+
<li>David Palanca &lt;<a class="reference external" href="mailto:davidpalanca&#64;grupoisonor.es">davidpalanca&#64;grupoisonor.es</a>&gt;</li>
530531
<li><a class="reference external" href="https://www.greenice.com">Greenice</a>:<ul>
531532
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
532533
</ul>
@@ -544,7 +545,9 @@ <h2><a class="toc-backref" href="#toc-entry-11">Other credits</a></h2>
544545
<div class="section" id="maintainers">
545546
<h2><a class="toc-backref" href="#toc-entry-12">Maintainers</a></h2>
546547
<p>This module is maintained by the OCA.</p>
547-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
548+
<a class="reference external image-reference" href="https://odoo-community.org">
549+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
550+
</a>
548551
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
549552
mission is to support the collaborative development of Odoo features and
550553
promote its widespread use.</p>

0 commit comments

Comments
 (0)