Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions connector_importer_product/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ Connector Importer Product
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--interfaces-lightgray.png?logo=github
:target: https://github.com/OCA/connector-interfaces/tree/16.0/connector_importer_product
:target: https://github.com/OCA/connector-interfaces/tree/18.0/connector_importer_product
:alt: OCA/connector-interfaces
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/connector-interfaces-16-0/connector-interfaces-16-0-connector_importer_product
:target: https://translation.odoo-community.org/projects/connector-interfaces-18-0/connector-interfaces-18-0-connector_importer_product
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector-interfaces&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector-interfaces&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Ease definition of product imports using `connector_importer`.
Ease definition of product imports using connector_importer.

Supported imports:

* products
* product attributes
* product attribute values
* product categories
* product packaging
* product supplier info
- products
- product attributes
- product attribute values
- product categories
- product packaging
- product supplier info

**Table of contents**

Expand All @@ -47,37 +47,37 @@ Supported imports:
Known issues / Roadmap
======================

* get rid of supplier info specific importer
* find a flexible way to define matching products
- get rid of supplier info specific importer
- find a flexible way to define matching products

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-interfaces/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/connector-interfaces/issues/new?body=module:%20connector_importer_product%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/connector-interfaces/issues/new?body=module:%20connector_importer_product%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~
-------

* Camptocamp

Contributors
~~~~~~~~~~~~
------------

* Simone Orsi <simahawk@gmail.com>
* Sébastien Alix <sebastien.alix@camptocamp.com>
* Jacques-Etienne Baudoux <je@bcim.be>
* Matthieu Méquignon <matthieu.mequignon@camptocamp.com>
- Simone Orsi <simahawk@gmail.com>
- Sébastien Alix <sebastien.alix@camptocamp.com>
- Jacques-Etienne Baudoux <je@bcim.be>
- Matthieu Méquignon <matthieu.mequignon@camptocamp.com>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -89,6 +89,6 @@ 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.

This module is part of the `OCA/connector-interfaces <https://github.com/OCA/connector-interfaces/tree/16.0/connector_importer_product>`_ project on GitHub.
This module is part of the `OCA/connector-interfaces <https://github.com/OCA/connector-interfaces/tree/18.0/connector_importer_product>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion connector_importer_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Connector Importer Product",
"summary": "Ease definition of product imports using `connector_importer`.",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Tools",
"website": "https://github.com/OCA/connector-interfaces",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import re
import unicodedata

from odoo import _

from odoo.addons.component.core import Component
from odoo.addons.connector_importer.log import logger
from odoo.addons.connector_importer.utils.misc import sanitize_external_id
Expand Down Expand Up @@ -33,6 +31,19 @@ def odoo_post_create(self, odoo_record, values, orig_values):
def odoo_post_write(self, odoo_record, values, orig_values):
self._update_template_attributes(odoo_record, values, orig_values)

def odoo_pre_write(self, odoo_record, values, orig_values):
# When updating product.product records, product_tmpl_id is set to False in values
# if not specified in the import type. But we don't want to set it to False
# as the value already exists in the odoo_record
if (
"product_tmpl_id" not in orig_values
and "product_tmpl_id" in odoo_record._fields
and odoo_record.product_tmpl_id
):
values["product_tmpl_id"] = odoo_record.product_tmpl_id.id

return super().odoo_pre_write(odoo_record, values, orig_values)

def odoo_create(self, values, orig_values):
odoo_record = super().odoo_create(values, orig_values)
# Set the external ID for the template if necessary
Expand All @@ -44,8 +55,9 @@ def _handle_template_xid(self, odoo_record, values, orig_values):
"""Create the xid for the template if needed.

The xid for the variant has been already created by `odoo_create`.
If the template is identified via xid using the column `xid::product_tmpl_id`
we must create this reference or other variant lines won't use the same template.
If the template is identified via xid using the column
`xid::product_tmpl_id`, we must create this reference
or other variant lines won't use the same template.
"""
if self.must_generate_xmlid and orig_values.get("xid::product_tmpl_id"):
tmpl_xid = sanitize_external_id(orig_values.get("xid::product_tmpl_id"))
Expand Down Expand Up @@ -112,6 +124,8 @@ def _update_template_attributes(self, odoo_record, values, orig_values):
# and B, we cannot import a second variant V2 with attributes A and C
# for instance, attributes have to be the same among all variants of a
# template)
if not attr_values_to_import_ids:
return
attr_values_to_import = self.env["product.attribute.value"].browse(
attr_values_to_import_ids
)
Expand All @@ -128,7 +142,7 @@ def _update_template_attributes(self, odoo_record, values, orig_values):
)
if existing_variant and attrs_to_import != existing_attrs:
raise ValueError(
_(
self.env._(
"Product '%(code)s' has not the same attributes "
"than '%(existing_code)s'. "
"Unable to import it.",
Expand All @@ -142,7 +156,7 @@ def _update_template_attributes(self, odoo_record, values, orig_values):
# or create it if none is found
attr = attr_value.attribute_id
tpl_attr_line = template.attribute_line_ids.filtered(
lambda l: l.attribute_id == attr
lambda line, attr=attr_value.attribute_id: line.attribute_id == attr
)
if not tpl_attr_line:
tpl_attr_line = TplAttrLine.create(
Expand Down Expand Up @@ -187,7 +201,7 @@ def _update_template_attributes(self, odoo_record, values, orig_values):
)
if combination_indices and existing_product:
raise ValueError(
_(
self.env._(
"Product '%(code)s' "
"seems to be a duplicate of '%(existing_code)s' (same attributes). "
"Unable to import it.",
Expand Down Expand Up @@ -220,7 +234,8 @@ def _find_or_create_attr_value(self, attr, attr_column, orig_values):
1. search by name
2. search by xid, assuming the value itself is already an xid.
3. search by composed xid, assuming the value is the last part of an xid.
The first part is computed as: `__setup__.$product_attr_xid_value_$col_value`.
The first part is computed as:
`__setup__.$product_attr_xid_value_$col_value`.
For instance, a column `product_attr_Size` could have the values
"S" , "M", "L" and they will be converted
to find their matching attributes, like this:
Expand Down
74 changes: 36 additions & 38 deletions connector_importer_product/data/import_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
<!-- Copyright 2022 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="import_type_product_category" model="import.type">
<field name="name">Product Category</field>
<field name="key">product_category</field>
<field name="options">
<record id="import_type_product_category" model="import.type">
<field name="name">Product Category</field>
<field name="key">product_category</field>
<field name="options">
- model: product.category
options:
importer:
odoo_unique_key: id
mapper:
name: importer.mapper.dynamic
</field>
</record>
</record>

<record id="import_type_product_attribute" model="import.type">
<field name="name">Product Attribute</field>
<field name="key">product_attribute</field>
<field name="options">
<record id="import_type_product_attribute" model="import.type">
<field name="name">Product Attribute</field>
<field name="key">product_attribute</field>
<field name="options">
- model: product.attribute
options:
importer:
Expand All @@ -29,12 +28,12 @@
translatable_keys:
- name
</field>
</record>
</record>

<record id="import_type_product_attribute_value" model="import.type">
<field name="name">Import Product Attribute Value</field>
<field name="key">product_attribute_value</field>
<field name="options">
<record id="import_type_product_attribute_value" model="import.type">
<field name="name">Import Product Attribute Value</field>
<field name="key">product_attribute_value</field>
<field name="options">
- model: product.attribute.value
options:
importer:
Expand All @@ -47,25 +46,25 @@
translatable_keys:
- name
</field>
</record>
</record>

<record id="import_type_product_product" model="import.type">
<field name="name">Import Product</field>
<field name="key">product_product</field>
<field name="options">
<record id="import_type_product_product" model="import.type">
<field name="name">Import Product</field>
<field name="key">product_product</field>
<field name="options">
- model: product.product
options:
importer:
odoo_unique_key: default_code
mapper:
name: product.product.mapper
</field>
</record>
</record>

<record id="import_type_product_supplierinfo" model="import.type">
<field name="name">Import Product Supplier Info</field>
<field name="key">product_supplierinfo</field>
<field name="options">
<record id="import_type_product_supplierinfo" model="import.type">
<field name="name">Import Product Supplier Info</field>
<field name="key">product_supplierinfo</field>
<field name="options">
- model: res.partner
options:
importer:
Expand All @@ -86,25 +85,25 @@
mapper:
name: product.supplierinfo.mapper
</field>
</record>
</record>

<record id="import_type_product_packaging" model="import.type">
<field name="name">Import Product Packaging</field>
<field name="key">product_packaging</field>
<field name="options">
<record id="import_type_product_packaging" model="import.type">
<field name="name">Import Product Packaging</field>
<field name="key">product_packaging</field>
<field name="options">
- model: product.packaging
options:
importer:
odoo_unique_key: id
mapper:
name: importer.mapper.dynamic
</field>
</record>
</record>

<record id="import_type_product_product_all_in_one" model="import.type">
<field name="name">Import Product - all in one</field>
<field name="key">product_product_all_in_one</field>
<field name="options">
<record id="import_type_product_product_all_in_one" model="import.type">
<field name="name">Import Product - all in one</field>
<field name="key">product_product_all_in_one</field>
<field name="options">
- model: product.product
options:
importer:
Expand Down Expand Up @@ -135,7 +134,7 @@
source_key_prefix: supplier.
</field>

<!--
<!--
Example of pkg import in all-in-one if the unique key for product.product is `id`
- model: product.packaging
options:
Expand All @@ -144,6 +143,5 @@
mapper:
name: importer.mapper.dynamic
-->
</record>

</record>
</odoo>
10 changes: 4 additions & 6 deletions connector_importer_product/demo/import_backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
<!-- Copyright 2022 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="demo_import_backend" model="import.backend">
<field name="name">Import Backend demo</field>
<field name="version">1.0</field>
</record>

<record id="demo_import_backend" model="import.backend">
<field name="name">Import Backend demo</field>
<field name="version">1.0</field>
</record>
</odoo>
Loading