Skip to content

Commit

Permalink
[IMP] connector_oxigesti: add product attribute fields to export
Browse files Browse the repository at this point in the history
  • Loading branch information
eantones committed Sep 16, 2023
1 parent a165305 commit e293eb6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions connector_oxigesti/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Contributors

* Eric Antones <[email protected]>
* Kilian Niubo <[email protected]>
* Frank Cespedes <[email protected]>



Expand Down
1 change: 1 addition & 0 deletions connector_oxigesti/models/oxigesti_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# 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",
),
]
5 changes: 5 additions & 0 deletions connector_oxigesti/models/oxigesti_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion connector_oxigesti/models/product_product/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ 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
from %(schema)s.Odoo_Articulos_Generales a
"""

Expand Down
15 changes: 15 additions & 0 deletions connector_oxigesti/models/product_product/export_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,18 @@ def Archivado(self, record):
@mapping
def Eliminado(self, record):
return {"Eliminado": 0}

@mapping
def Atributos(self, record):
attributes = {}

Check warning on line 95 in connector_oxigesti/models/product_product/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_product/export_mapper.py#L95

Added line #L95 was not covered by tests
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[

Check warning on line 103 in connector_oxigesti/models/product_product/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_product/export_mapper.py#L103

Added line #L103 was not covered by tests
attribute_map.oxigesti_attribute
] = ptav.product_attribute_value_id.name
return attributes or None

Check warning on line 106 in connector_oxigesti/models/product_product/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_product/export_mapper.py#L106

Added line #L106 was not covered by tests
2 changes: 2 additions & 0 deletions connector_oxigesti/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions connector_oxigesti/views/oxigesti_backend_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@
<field name="warehouse_id" />
</group>
</page>
<page name="mappings" string="Mappings">
<group string="Product Attributes">
<field name="product_attribute_map_ids" nolabel="1">
<tree editable="bottom">
<field name="attribute_id" />
<field name="oxigesti_attribute" />
</tree>
</field>
</group>
</page>
</notebook>
</sheet>
</form>
Expand Down

0 comments on commit e293eb6

Please sign in to comment.