Skip to content

Commit

Permalink
[FIX] connetor_prestashop: valid_ean and detailed_type when create pr…
Browse files Browse the repository at this point in the history
…oducts
  • Loading branch information
davidpalanca committed May 23, 2024
1 parent 036340f commit e1052c8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions connector_prestashop/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Contributors
* Marc Poch <[email protected]>
* JesusVMayor <[email protected]>
* Hai Lang <[email protected]>
* David Palanca <[email protected]>

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

Expand Down
10 changes: 8 additions & 2 deletions connector_prestashop/models/product_product/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,20 @@ def default_code(self, record):
@mapping
def barcode(self, record):
barcode = record.get("barcode") or record.get("ean13")
check_ean = self.env["barcode.nomenclature"].check_ean
barcode_nomenclature_model = self.env["barcode.nomenclature"]

def is_valid_ean(barcode):
"""Validates if a barcode is a valid EAN."""
return barcode_nomenclature_model.check_encoding(barcode, "ean13")

if barcode in ["", "0"]:
backend_adapter = self.component(
usage="backend.adapter", model_name="prestashop.product.template"
)
template = backend_adapter.read(record["id_product"])
barcode = template.get("barcode") or template.get("ean13")
if barcode and barcode != "0" and check_ean(barcode):

if barcode and barcode != "0" and is_valid_ean(barcode):
return {"barcode": barcode}
return {}

Expand Down
11 changes: 11 additions & 0 deletions connector_prestashop/models/product_template/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def update_prestashop_quantities(self):
).recompute_prestashop_qty()
return True

@api.model
def create(self, vals):
if "type" in vals:
if vals["type"] == "product":
vals["detailed_type"] = "product"
elif vals["type"] == "consu":
vals["detailed_type"] = "consu"
elif vals["type"] == "service":
vals["detailed_type"] = "service"
return super(ProductTemplate, self).create(vals)


class ProductQtyMixin(models.AbstractModel):
_name = "prestashop.product.qty.mixin"
Expand Down
8 changes: 7 additions & 1 deletion connector_prestashop/models/product_template/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,17 @@ def company_id(self, record):
def barcode(self, record):
if self.has_combinations(record):
return {}

barcode = record.get("barcode") or record.get("ean13")
if barcode in ["", "0"]:
return {}
if self.env["barcode.nomenclature"].check_ean(barcode):

barcode_nomenclature = self.env["barcode.nomenclature"]
if barcode_nomenclature.check_encoding(
barcode, "ean13"
) or barcode_nomenclature.check_encoding(barcode, "ean8"):
return {"barcode": barcode}

return {}

def _get_tax_ids(self, record):
Expand Down
13 changes: 8 additions & 5 deletions connector_prestashop/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

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

span.problematic {
span.problematic, pre.problematic {
color: red }

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

0 comments on commit e1052c8

Please sign in to comment.