Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] connector_oxigesti: add product attributes and lot info #300

Closed
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
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/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"sale_line_partner_description",
"sale_specific_order_date",
"oxigen_stock_alternate_lot",
"oxigen_mrp",
],
"external_dependencies": {
"python": [
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
8 changes: 7 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,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
"""

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 @@
@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
5 changes: 4 additions & 1 deletion connector_oxigesti/models/stock_production_lot/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class StockProductionLotAdapter(Component):
_apply_on = "oxigesti.stock.production.lot"

_sql = """select l.CodigoArticulo, l.Lote, l.nos, l.nos_unknown,
l.dn, l.dn_unknown, l.write_date
l.dn, l.dn_unknown, l.Fabricante, l.Peso,
l.FechaFabricacion, l.FechaRetimbrado,
l.FechaProximoRetimbrado, l.FechaCaducidad,
l.write_date
from %(schema)s.Odoo_Articulos_Lotes l
"""

Expand Down
15 changes: 14 additions & 1 deletion connector_oxigesti/models/stock_production_lot/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ def _compute_oxigesti_readonly(self):
default=fields.Datetime.now,
)

@api.depends("name", "product_id", "nos", "dn", "nos_unknown", "dn_unknown")
@api.depends(
"name",
"product_id",
"nos",
"dn",
"nos_unknown",
"dn_unknown",
"manufacturer_id",
"weight",
"manufacture_date",
"retesting_date",
"next_retesting_date",
"removal_date",
)
def _compute_oxigesti_write_date(self):
for rec in self:
rec.oxigesti_write_date = fields.Datetime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.addons.component.core import Component
from odoo.addons.connector.components.mapper import mapping
from odoo.addons.connector.components.mapper import follow_m2o_relations, mapping, none


class StockProductionLotExportMapper(Component):
Expand All @@ -14,6 +14,12 @@ class StockProductionLotExportMapper(Component):

direct = [
("name", "Lote"),
(none(follow_m2o_relations("manufacturer_id.name")), "Fabricante"),
(none("weight"), "Peso"),
(none("manufacture_date"), "FechaFabricacion"),
(none("retesting_date"), "FechaRetimbrado"),
(none("next_retesting_date"), "FechaProximoRetimbrado"),
(none("removal_date"), "FechaCaducidad"),
]

@mapping
Expand Down
37 changes: 37 additions & 0 deletions connector_oxigesti/models/stock_production_lot/import_mapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright NuoBiT Solutions - Kilian Niubo <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import _
from odoo.exceptions import ValidationError

from odoo.addons.component.core import Component
from odoo.addons.connector.components.mapper import mapping, only_create
Expand All @@ -12,6 +13,14 @@

_apply_on = "oxigesti.stock.production.lot"

direct = [
("Peso", "weight"),
("FechaFabricacion", "manufacture_date"),
("FechaRetimbrado", "retesting_date"),
("FechaProximoRetimbrado", "next_retesting_date"),
("FechaCaducidad", "removal_date"),
]

@mapping
def backend_id(self, record):
return {"backend_id": self.backend_record.id}
Expand Down Expand Up @@ -73,6 +82,34 @@
values["dn_unknown"] = record["dn_unknown"]
return values

# TODO: REVIEW: improve this mapping, exists the possibility that the
# manufacturer has a different name in Odoo than in Oxigesti
@mapping
def manufacturer_id(self, record):
if record["Fabricante"]:
manufacturer = self.env["res.partner"].search(

Check warning on line 90 in connector_oxigesti/models/stock_production_lot/import_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/stock_production_lot/import_mapper.py#L90

Added line #L90 was not covered by tests
[
("name", "=", record["Fabricante"]),
("company_id", "in", (False, self.backend_record.company_id.id)),
]
)
if not manufacturer:
raise ValidationError(

Check warning on line 97 in connector_oxigesti/models/stock_production_lot/import_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/stock_production_lot/import_mapper.py#L97

Added line #L97 was not covered by tests
_("Manufacturer (%s) does not exist with this name on Odoo")
% (record["Fabricante"],)
)
if len(manufacturer) > 1:
raise ValidationError(

Check warning on line 102 in connector_oxigesti/models/stock_production_lot/import_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/stock_production_lot/import_mapper.py#L102

Added line #L102 was not covered by tests
_(
"Found more than one manufacturer (%i) with "
"the same name (%s) in Odoo"
)
% (len(manufacturer), record["Fabricante"])
)
return {"manufacturer_id": manufacturer.id}

Check warning on line 109 in connector_oxigesti/models/stock_production_lot/import_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/stock_production_lot/import_mapper.py#L109

Added line #L109 was not covered by tests
else:
return {"manufacturer_id": None}

Check warning on line 111 in connector_oxigesti/models/stock_production_lot/import_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/stock_production_lot/import_mapper.py#L111

Added line #L111 was not covered by tests

@mapping
def oxigesti_write_date(self, record):
return {"oxigesti_write_date": record["write_date"]}
Expand Down
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
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ openupgradelib@git+https://github.com/OCA/openupgradelib.git@master
pyveloedi@git+https://github.com/nuobit/pyveloedi3.git@master
odoo14-addon-oxigen_stock_alternate_lot@git+https://github.com/oxigensalud/[email protected]#subdirectory=setup/oxigen_stock_alternate_lot
odoo14-addon-pricelist_massive_update@git+https://github.com/oxigensalud/[email protected]#subdirectory=setup/pricelist_massive_update
odoo14-addon-oxigen_mrp@git+https://github.com/oxigensalud/[email protected]_mrp-new_module#subdirectory=setup/oxigen_mrp
odoo14-addon-oxigen_stock@git+https://github.com/oxigensalud/[email protected]#subdirectory=setup/oxigen_stock
Loading