[IMP] data_nature_importer: add eCommerce cathegories

This commit is contained in:
Niels Göttsch 2026-05-21 10:31:34 +02:00 committed by madmooose
parent cb2d42f3ea
commit a429bf26bb
7 changed files with 5222 additions and 24 deletions

View file

@ -8,6 +8,7 @@
"depends": ["product", "queue_job", "website_sale"],
"data": [
"security/ir.model.access.csv",
"data/datanature_warengruppen.xml",
"views/product_template_views.xml",
"views/res_config_settings_views.xml",
],

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,3 @@
from . import product_public_category
from . import product_template
from . import res_config_settings

View file

@ -0,0 +1,11 @@
from odoo import fields, models
class ProductPublicCategory(models.Model):
_inherit = "product.public.category"
datanature_warengruppe_id = fields.Char(
string="DataNature Warengruppe ID",
index=True,
copy=False,
)

View file

@ -12,9 +12,9 @@ Image.MAX_IMAGE_PIXELS = 2 * 189135000 # set custom limit for large images
class ProductTemplate(models.Model):
_inherit = "product.template"
def action_sync_datanature_image(self):
def action_sync_datanature_information(self):
for product in self:
product.with_delay()._sync_dn_images()
product._sync_dn_information()
def _get_dn_metadata(self):
self.ensure_one()
@ -25,21 +25,32 @@ class ProductTemplate(models.Model):
return False
return metadata[0]
def _sync_dn_images(self):
def _sync_dn_information(self):
self.ensure_one()
metadata = self._get_dn_metadata()
if not metadata or not metadata.get("images"):
if not metadata:
return False
self._sync_dn_category(metadata)
self._sync_dn_images(metadata)
return True
def _sync_dn_category(self, metadata):
warengruppe_id = metadata.get("warengruppe_id")
if not warengruppe_id:
return
category = self.env["product.public.category"].search(
[("datanature_warengruppe_id", "=", warengruppe_id)], limit=1
)
if category and category not in self.public_categ_ids:
self.public_categ_ids = [(4, category.id)]
def _sync_dn_images(self, metadata):
images = metadata.get("images")
if not images:
return False
image_id = None
for image in images:
image_id = image.get("id")
if image.get("mime_type") not in [
"image/jpeg",
"image/png",
]:
if image.get("mime_type") not in ["image/jpeg", "image/png"]:
continue
image_data = dn_utils.get_datanature_image(self, image_id, token=None)
if not image_data:
@ -48,14 +59,11 @@ class ProductTemplate(models.Model):
self.image_1920 = image_data
else:
ProductImage = self.env["product.image"]
if (
ProductImage.search_count(
[
("product_tmpl_id", "=", self.id),
("name", "=", f"DATA Nature Image: {image_id}"),
]
)
> 0
if ProductImage.search_count(
[
("product_tmpl_id", "=", self.id),
("name", "=", f"DATA Nature Image: {image_id}"),
]
):
continue
ProductImage.create(

View file

@ -70,6 +70,15 @@ def _parse_products(xml_bytes):
"zutatenlegende_txt": prod.findtext(
"dn:zut_zutatenlegende_txt", default="", namespaces=ns
),
"warengruppe_id": prod.findtext(
"dn:pbm_warengruppe_id", default="", namespaces=ns
),
"warengruppe_kuerzel": prod.findtext(
"dn:pbm_warengruppe_kuerzel", default="", namespaces=ns
),
"warengruppe_pfad": prod.findtext(
"dn:pbm_warengruppe_pfad", default="", namespaces=ns
),
"beschreibung_kurz": prod.findtext(
"dn:markinf_produktbeschreibung_kurz", default="", namespaces=ns
),

View file

@ -1,13 +1,11 @@
<odoo>
<record id="model_product_template_action_sync_image" model="ir.actions.server">
<field name="name">Sync Datanature Image</field>
<field name="model_id" ref="product.model_product_template"/> <field
name="binding_model_id"
ref="product.model_product_template"
/>
<record id="model_product_template_action_sync_information" model="ir.actions.server">
<field name="name">Sync DataNature Information</field>
<field name="model_id" ref="product.model_product_template"/>
<field name="binding_model_id" ref="product.model_product_template"/>
<field name="state">code</field>
<field name="code">
action = records.action_sync_datanature_image()
action = records.action_sync_datanature_information()
</field>
</record>
</odoo>