-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] connector_oxigesti: export manufacturing and unbuild orders
- Loading branch information
Showing
16 changed files
with
382 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) --> | ||
<odoo> | ||
<record id="mrp_production_form_view" model="ir.ui.view"> | ||
<field name="name">mrp.production.connector.form</field> | ||
<field name="model">mrp.production</field> | ||
<field name="inherit_id" ref="mrp.mrp_production_form_view" /> | ||
<field | ||
name="groups_id" | ||
eval="[(4, ref('connector.group_connector_manager'))]" | ||
/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="/form/sheet/notebook" position="inside"> | ||
<!-- change the invisible attribute to 0 when used | ||
in submodules --> | ||
<page string="Connectors" name="connector" invisible="1" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from . import exporter | ||
from . import adapter | ||
from . import export_mapper | ||
from . import binder | ||
from . import binding | ||
|
||
# from . import listener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class MrpProductionAdapter(Component): | ||
_name = "oxigesti.mrp.production.adapter" | ||
_inherit = "oxigesti.adapter" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
_sql = """select a.CodigoOrdenProduccion, a.FechaProduccion, a.EsMontaje, | ||
a.CodigoBotellaVacia, a.LoteBotellaVacia, | ||
a.CodigoCilindro, a.LoteCilindro, a.CodigoValvula, | ||
a.LoteValvula | ||
from %(schema)s.Odoo_Orden_Produccion a | ||
""" | ||
|
||
_sql_update = """update s | ||
set %(qset)s | ||
from %(schema)s.Odoo_Orden_Produccion s | ||
where s.CodigoOrdenProduccion = %%(CodigoOrdenProduccion)s | ||
""" | ||
|
||
_sql_insert = """insert into %(schema)s.Odoo_Orden_Produccion | ||
(%(fields)s) | ||
output %(retvalues)s | ||
values (%(phvalues)s) | ||
""" | ||
|
||
_id = ("CodigoOrdenProduccion",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class MrpProductionBinder(Component): | ||
_name = "oxigesti.mrp.production.binder" | ||
_inherit = "oxigesti.binder" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
def _get_external_id(self, binding): | ||
if not self._is_binding(binding): | ||
raise Exception("The source object %s must be a binding" % binding._name) | ||
|
||
product_binder = self.binder_for("oxigesti.mrp.production") | ||
product_external_id = product_binder.to_external( | ||
binding.odoo_id.product_id, wrap=True | ||
) | ||
|
||
external_id = None | ||
if product_external_id: | ||
product_adapter = self.component( | ||
usage="backend.adapter", model_name="oxigesti.mrp.production" | ||
) | ||
codigo_articulo = product_adapter.id2dict(product_external_id)[ | ||
"CodigoOrdenProduccion" | ||
] | ||
external_id = [codigo_articulo, binding.name] | ||
|
||
return external_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import api, fields, models | ||
|
||
|
||
class MrpProduction(models.Model): | ||
_inherit = "mrp.production" | ||
|
||
oxigesti_bind_ids = fields.One2many( | ||
comodel_name="oxigesti.mrp.production", | ||
inverse_name="odoo_id", | ||
string="Oxigesti Bindings", | ||
) | ||
|
||
|
||
class MrpProductionBinding(models.Model): | ||
_name = "oxigesti.mrp.production" | ||
_inherit = "oxigesti.binding" | ||
_inherits = {"mrp.production": "odoo_id"} | ||
_description = "Product Mrp Production" | ||
|
||
odoo_id = fields.Many2one( | ||
comodel_name="mrp.production", | ||
string="Productions", | ||
required=True, | ||
ondelete="cascade", | ||
) | ||
|
||
@api.model | ||
def export_data(self, backend, since_date): | ||
domain = [ | ||
("company_id", "=", backend.company_id.id), | ||
("product_id.mrp_type", "=", "empty_gas_bottle"), | ||
("state", "=", "done"), | ||
] | ||
if since_date: | ||
domain += [("write_date", ">", since_date)] | ||
self.with_delay().export_batch(backend, domain=domain) | ||
|
||
def resync(self): | ||
for record in self: | ||
with record.backend_id.work_on(record._name) as work: | ||
binder = work.component(usage="binder") | ||
relation = binder.unwrap_binding(self) | ||
func = record.export_record | ||
if record.env.context.get("connector_delay"): | ||
func = record.export_record.delay | ||
func(record.backend_id, relation) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# 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 follow_m2o_relations, mapping, none | ||
|
||
|
||
class MrpProductionExportMapper(Component): | ||
_name = "oxigesti.mrp.production.export.mapper" | ||
_inherit = "oxigesti.export.mapper" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
direct = [ | ||
("name", "CodigoOrdenProduccion"), | ||
(none("date_planned_start"), "FechaProduccion"), | ||
(none(follow_m2o_relations("lot_producing_id.name")), "LoteBotellaVacia"), | ||
(none(follow_m2o_relations("product_id.code")), "CodigoBotellaVacia"), | ||
] | ||
|
||
@mapping | ||
def EsMontaje(self, record): | ||
unbuild_count = self.env["mrp.unbuild"].search_count( | ||
[("mo_id", "=", record.odoo_id.id), ("state", "=", "done")] | ||
) | ||
return {"EsMontaje": 0 if unbuild_count > 1 else 1} | ||
|
||
@mapping | ||
def Codigo(self, record): | ||
cylinder_product = record.move_raw_ids.product_id.filtered( | ||
lambda x: x.mrp_type == "cylinder" | ||
) | ||
valve_product = record.move_raw_ids.product_id.filtered( | ||
lambda x: x.mrp_type == "valve" | ||
) | ||
if len(cylinder_product) == 0 or len(valve_product) == 0: | ||
raise AssertionError( | ||
"Production of empty gas bottle type without" | ||
" cylinder or valve product: %s" % record.name | ||
) | ||
if len(cylinder_product) > 1 or len(valve_product) > 1: | ||
raise AssertionError( | ||
"Production of empty gas bottle type with" | ||
" more than one cylinder or valve product: %s" % record.name | ||
) | ||
return { | ||
"CodigoCilindro": cylinder_product.code, | ||
"CodigoValvula": valve_product.code, | ||
} | ||
|
||
@mapping | ||
def Lote(self, record): | ||
cylinder_mr = record.move_raw_ids.filtered( | ||
lambda x: x.product_id.mrp_type == "cylinder" and x.quantity_done > 0 | ||
) | ||
valve_mr = record.move_raw_ids.filtered( | ||
lambda x: x.product_id.mrp_type == "valve" and x.quantity_done > 0 | ||
) | ||
if ( | ||
len(cylinder_mr) > 1 | ||
or len(valve_mr) > 1 | ||
or sum(cylinder_mr.mapped("quantity_done")) > 1 | ||
or sum(valve_mr.mapped("quantity_done")) > 1 | ||
): | ||
raise AssertionError( | ||
"The empty gas bottle (%s) has been created with" | ||
" more than one valve or cylinder" % record.name | ||
) | ||
if len(cylinder_mr.move_line_ids) > 1 or len(valve_mr.move_line_ids) > 1: | ||
raise AssertionError( | ||
"You have a component with more than one serial" | ||
" number to generate: %s" % record.name | ||
) | ||
return { | ||
"LoteCilindro": cylinder_mr.move_line_ids.lot_id.name or None, | ||
"LoteValvula": valve_mr.move_line_ids.lot_id.name or None, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class MrpProductionDelayedBatchExporter(Component): | ||
"""Export the Oxigesti Productions. | ||
For every production in the list, a delayed job is created. | ||
""" | ||
|
||
_name = "oxigesti.mrp.production.delayed.batch.exporter" | ||
_inherit = "oxigesti.delayed.batch.exporter" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
|
||
class MrpProductionDirectBatchExporter(Component): | ||
"""Export the Oxigesti Productions. | ||
For every production in the list, execute inmediately. | ||
""" | ||
|
||
_name = "oxigesti.mrp.production.direct.batch.exporter" | ||
_inherit = "oxigesti.direct.batch.exporter" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
|
||
class MrpProductionExporter(Component): | ||
_name = "oxigesti.mrp.production.exporter" | ||
_inherit = "oxigesti.exporter" | ||
|
||
_apply_on = "oxigesti.mrp.production" | ||
|
||
def _export_dependencies(self): | ||
binder = self.binder_for("oxigesti.product.product") | ||
relation = self.binding.with_context(active_test=False).product_id | ||
if not binder.to_external(self.binding.product_id, wrap=True): | ||
exporter = self.component( | ||
usage="record.exporter", model_name=binder.model._name | ||
) | ||
exporter.run(relation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.