From b56a65d3c16183078420585420846d30ca407c95 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Sat, 16 Sep 2023 18:32:42 +0200 Subject: [PATCH] [IMP] connector_oxigesti: add product attribute fields to export --- connector_oxigesti/README.rst | 1 + .../models/oxigesti_backend/__init__.py | 1 + .../backend_product_attribute_map.py | 47 +++++++++++++++++++ .../models/oxigesti_backend/common.py | 5 ++ .../models/product_product/adapter.py | 8 +++- .../models/product_product/export_mapper.py | 15 ++++++ .../security/ir.model.access.csv | 2 + .../views/oxigesti_backend_view.xml | 10 ++++ 8 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 connector_oxigesti/models/oxigesti_backend/backend_product_attribute_map.py diff --git a/connector_oxigesti/README.rst b/connector_oxigesti/README.rst index 7c841131c..771a650b1 100644 --- a/connector_oxigesti/README.rst +++ b/connector_oxigesti/README.rst @@ -24,6 +24,7 @@ Contributors * Eric Antones * Kilian Niubo +* Frank Cespedes diff --git a/connector_oxigesti/models/oxigesti_backend/__init__.py b/connector_oxigesti/models/oxigesti_backend/__init__.py index f72b58532..0cacb9672 100644 --- a/connector_oxigesti/models/oxigesti_backend/__init__.py +++ b/connector_oxigesti/models/oxigesti_backend/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from . import common +from . import backend_product_attribute_map diff --git a/connector_oxigesti/models/oxigesti_backend/backend_product_attribute_map.py b/connector_oxigesti/models/oxigesti_backend/backend_product_attribute_map.py new file mode 100644 index 000000000..82a551037 --- /dev/null +++ b/connector_oxigesti/models/oxigesti_backend/backend_product_attribute_map.py @@ -0,0 +1,47 @@ +# Copyright NuoBiT Solutions - Frank Cespedes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +import logging + +from odoo import fields, models + +_logger = logging.getLogger(__name__) + + +class OxigestiBackendProductAttributeMap(models.Model): + _name = "oxigesti.backend.product.attribute.map" + + backend_id = fields.Many2one( + comodel_name="oxigesti.backend", + string="Oxigesti Backend", + ondelete="cascade", + ) + + attribute_id = fields.Many2one( + comodel_name="product.attribute", + string="Odoo Product Attribute", + required=True, + ondelete="restrict", + ) + + oxigesti_attribute = fields.Char( + string="Oxigesti Attribute", + required=True, + ) + + _sql_constraints = [ + ( + "uniq", + "unique(backend_id, attribute_id, external_id)", + "Attribute mapping line must be unique", + ), + ( + "attribute_uniq", + "unique(backend_id, attribute_id)", + "Odoo Attribute used in another map line", + ), + ( + "external_uniq", + "unique(backend_id, external_id)", + "External ID used in another map line", + ), + ] diff --git a/connector_oxigesti/models/oxigesti_backend/common.py b/connector_oxigesti/models/oxigesti_backend/common.py index da6567146..014033c62 100644 --- a/connector_oxigesti/models/oxigesti_backend/common.py +++ b/connector_oxigesti/models/oxigesti_backend/common.py @@ -77,6 +77,11 @@ def _select_state(self): ) active = fields.Boolean(string="Active", default=True) state = fields.Selection(selection="_select_state", string="State", default="draft") + product_attribute_map_ids = fields.One2many( + comodel_name="oxigesti.backend.product.attribute.map", + inverse_name="backend_id", + string="Product Attribute Map", + ) def button_reset_to_draft(self): self.ensure_one() diff --git a/connector_oxigesti/models/product_product/adapter.py b/connector_oxigesti/models/product_product/adapter.py index af1ef919c..af1dd955a 100644 --- a/connector_oxigesti/models/product_product/adapter.py +++ b/connector_oxigesti/models/product_product/adapter.py @@ -11,7 +11,13 @@ class ProductProductAdapter(Component): _apply_on = "oxigesti.product.product" _sql = """select a.CodigoArticulo, a.DescripcionArticulo, - a.Familia, a.CodigoAlternativo, a.Importe + a.Familia, a.CodigoAlternativo, a.Importe, a.Diametro, + a.ColorOjiva, a.AlojamientoValvula, a.Base, + a.CapacidadGeometrica, a.ColorCuerpo, a.PresionPrueba, + a.RoscaCollarinParaTulipa, a.TipoAleacion, + a.AcoplamientoSalida, a.PresionMaximaTrabajo, a.Sonda, + a.TomaRapida, a.Cromada, a.EsCompacta, a.EsResidual, + a.EsCaudal, a.PresionRotura, a.Comunicacion, a.Manometro from %(schema)s.Odoo_Articulos_Generales a """ diff --git a/connector_oxigesti/models/product_product/export_mapper.py b/connector_oxigesti/models/product_product/export_mapper.py index 0161778e4..598835dd4 100644 --- a/connector_oxigesti/models/product_product/export_mapper.py +++ b/connector_oxigesti/models/product_product/export_mapper.py @@ -89,3 +89,18 @@ def Archivado(self, record): @mapping def Eliminado(self, record): return {"Eliminado": 0} + + @mapping + def Atributos(self, record): + attributes = {} + for ptav in record.with_context( + lang=self.backend_record.lang_id.code + ).product_template_attribute_value_ids: + attribute_map = self.backend_record.product_attribute_map_ids.filtered( + lambda x: x.attribute_id == ptav.attribute_id + ) + if attribute_map: + attributes[ + attribute_map.oxigesti_attribute + ] = ptav.product_attribute_value_id.name + return attributes or None diff --git a/connector_oxigesti/security/ir.model.access.csv b/connector_oxigesti/security/ir.model.access.csv index 1f38e7e33..3a22055ec 100644 --- a/connector_oxigesti/security/ir.model.access.csv +++ b/connector_oxigesti/security/ir.model.access.csv @@ -16,3 +16,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink "access_oxigesti_stock_production_lot","oxigesti_stock_production_lot connector manager","model_oxigesti_stock_production_lot","connector.group_connector_manager",1,1,1,1 "access_oxigesti_stock_production_lot_group_user","oxigesti_stock_production_lot group_user","model_oxigesti_stock_production_lot","base.group_user",1,0,0,0 "access_oxigesti_backend","oxigesti_backend connector manager","model_oxigesti_backend","connector.group_connector_manager",1,1,1,1 +"access_oxigesti_backend_product_attribute_map","oxigesti_backend_product_attribute_map connector manager","model_oxigesti_backend_product_attribute_map","connector.group_connector_manager",1,1,1,1 +"access_oxigesti_backend_product_attribute_map_group_user","oxigesti_backend_product_attribute_map group_user","model_oxigesti_backend_product_attribute_map","base.group_user",1,1,1,1 diff --git a/connector_oxigesti/views/oxigesti_backend_view.xml b/connector_oxigesti/views/oxigesti_backend_view.xml index 51fd860ab..0811318eb 100644 --- a/connector_oxigesti/views/oxigesti_backend_view.xml +++ b/connector_oxigesti/views/oxigesti_backend_view.xml @@ -311,6 +311,16 @@ + + + + + + + + + +