-
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
15 changed files
with
396 additions
and
2 deletions.
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
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,21 @@ | ||
# 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) | ||
|
||
external_id = None | ||
if binding.odoo_id.product_id.default_code: | ||
external_id = [binding.odoo_id.product_id.default_code] | ||
|
||
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,86 @@ | ||
# 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 | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class MrpProduction(models.Model): | ||
_inherit = "mrp.production" | ||
|
||
oxigesti_bind_ids = fields.One2many( | ||
comodel_name="oxigesti.mrp.production", | ||
inverse_name="odoo_id", | ||
string="Oxigesti Bindings", | ||
) | ||
|
||
def _get_valid_components(self): | ||
fields = ["cylinder", "valve"] | ||
record = self.env["stock.move"] | ||
for mrp_type in fields: | ||
move_raw = self.move_raw_ids.filtered( | ||
lambda x: x.product_id.mrp_type == mrp_type and x.quantity_done > 0 | ||
) | ||
if len(move_raw.product_id) == 0: | ||
raise ValidationError( | ||
_("Production of empty gas bottle type without %s product: %s") | ||
% (mrp_type, self.name) | ||
) | ||
if len(move_raw) > 1 or sum(move_raw.mapped("quantity_done")) > 1: | ||
raise ValidationError( | ||
_( | ||
"The empty gas bottle (%s) has been created with" | ||
" more than one %s" | ||
) | ||
% (self.name, mrp_type) | ||
) | ||
if len(move_raw.move_line_ids) > 1: | ||
raise ValidationError( | ||
_( | ||
"You have a component with more than one serial" | ||
" number to generate: %s" | ||
) | ||
% self.name | ||
) | ||
if not move_raw.product_id.default_code: | ||
raise ValidationError( | ||
_("Internal Reference not set in product: %s") | ||
% move_raw.product_id.name | ||
) | ||
record |= move_raw | ||
return record | ||
|
||
|
||
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,56 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[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 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"), | ||
] | ||
|
||
@mapping | ||
def CodigoBotellaVacia(self, record): | ||
if not record.product_id.default_code: | ||
raise ValidationError( | ||
_("Internal Reference not set in product: %s") % record.product_id.name | ||
) | ||
return {"CodigoBotellaVacia": record.product_id.default_code} | ||
|
||
@mapping | ||
def EsMontaje(self, record): | ||
unbuild_count = self.env["mrp.unbuild"].search( | ||
[("mo_id", "=", record.odoo_id.id), ("state", "=", "done")] | ||
) | ||
if len(unbuild_count) > 1: | ||
raise ValidationError( | ||
_("The production %s has more than one unbuild. %s") | ||
% (record.name, unbuild_count.mapped("name")) | ||
) | ||
return {"EsMontaje": 0 if len(unbuild_count) > 0 else 1} | ||
|
||
@mapping | ||
def Componentes(self, record): | ||
binder = self.binder_for("oxigesti.mrp.production") | ||
mrp_production = binder.unwrap_binding(record) | ||
move_raws = mrp_production._get_valid_components() | ||
type_mrp = { | ||
"cylinder": ("CodigoCilindro", "LoteCilindro"), | ||
"valve": ("CodigoValvula", "LoteValvula"), | ||
} | ||
res = {} | ||
for move_raw in move_raws: | ||
code_key, lot_key = type_mrp.get(move_raw.product_id.mrp_type) | ||
res[code_key] = move_raw.product_id.default_code or None | ||
res[lot_key] = move_raw.move_line_ids.lot_id.name or None | ||
return res | ||
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,53 @@ | ||
# 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.mrp.production") | ||
mrp_production = binder.unwrap_binding(self.binding) | ||
items_dict = { | ||
"oxigesti.stock.production.lot": mrp_production.lot_producing_id | ||
| mrp_production._get_valid_components().move_line_ids.lot_id, | ||
"oxigesti.product.product": mrp_production.product_id | ||
| mrp_production._get_valid_components().product_id, | ||
} | ||
for binder_name, items in items_dict.items(): | ||
binder = self.binder_for(binder_name) | ||
for item in items: | ||
if not binder.to_external(item, wrap=True): | ||
exporter = self.component( | ||
usage="record.exporter", model_name=binder.model._name | ||
) | ||
exporter.run(item) | ||
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.