-
Notifications
You must be signed in to change notification settings - Fork 21
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][ADD] connector_oxigesti: export manufacturing and unbuild orders #301
Open
FrankC013
wants to merge
9
commits into
14.0
Choose a base branch
from
14.0-add-connector_oxigesti-export_mrp_production_unbuild
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2d02aa8
[ADD] connector_oxigesti: export manufacturing and unbuild orders
FrankC013 6ce883a
[IMP] test-requirements.txt
FrankC013 94443b6
[IMP] connector_oxigesti: add mrp lot fields to import/export
eantones 2b78ed0
[IMP] connector_oxigesti: add product attribute fields to export
eantones 53f92a7
[FIX] connector_oxigesti: show odoo id when the internal product refe…
FrankC013 9ff0536
[IMP] connector_oxigesti: manage if the content of the attribute matc…
FrankC013 0ea49d5
[REF] connector_oxigesti: store the code of the unbuild orders in Odo…
FrankC013 9db2d45
[FIX] connector_oxigesti: solve foreign key problems
FrankC013 1960b75
[FIX] connector_oxigesti: wrong mrp product type
eantones File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ Contributors | |
|
||
* Eric Antones <[email protected]> | ||
* Kilian Niubo <[email protected]> | ||
* Frank Cespedes <[email protected]> | ||
|
||
|
||
|
||
|
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 |
---|---|---|
|
@@ -121,6 +121,25 @@ class GenericAdapter(AbstractComponent): | |
_name = "oxigesti.adapter" | ||
_inherit = "oxigesti.crud.adapter" | ||
|
||
@property | ||
def PYTHON_TYPE_MAP(self): | ||
return { | ||
int: ["int"], | ||
float: ["float", "numeric"], | ||
str: ["nvarchar"], | ||
bool: ["bit"], | ||
} | ||
|
||
@property | ||
def MSSQL_TYPE_MAP(self): | ||
mssql_type_map = {} | ||
for k, v in self.PYTHON_TYPE_MAP.items(): | ||
for t in v: | ||
if t in mssql_type_map: | ||
raise ValidationError(_("Duplicated type %s in MSSQL_TYPE_MAP") % t) | ||
mssql_type_map[t] = k | ||
return mssql_type_map | ||
|
||
# private methods | ||
def _convert_dict(self, data, to_backend=True): | ||
if not isinstance(data, dict): | ||
|
@@ -228,6 +247,26 @@ def _exec_query(self, filters=None, fields=None, as_dict=True): | |
|
||
return res | ||
|
||
def get_headers(self): | ||
# prepare the sql and execute | ||
if not hasattr(self, "_sql_field_type"): | ||
raise ValidationError( | ||
_("The adapter %s doesn't have a _sql_field_type defined") % self._name | ||
) | ||
conn = self.conn() | ||
cr = conn.cursor() | ||
cr.execute(self._sql_field_type, dict(schema=self.schema)) | ||
res = {} | ||
for field, ttype in cr.fetchall(): | ||
if ttype not in self.MSSQL_TYPE_MAP: | ||
raise ValidationError( | ||
_("Unexpected type %s for field %s") % (ttype, field) | ||
Comment on lines
+262
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this line as a first if |
||
) | ||
res[field] = self.MSSQL_TYPE_MAP[ttype] | ||
cr.close() | ||
conn.close() | ||
return res | ||
|
||
def _check_uniq(self, data): | ||
uniq = set() | ||
for rec in data: | ||
|
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 |
---|---|---|
|
@@ -11,3 +11,4 @@ | |
from . import sale_order | ||
from . import account_invoice | ||
from . import stock_picking | ||
from . import mrp_production |
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.Id, a.CodigoOrdenProduccion, a.FechaProduccion, | ||
a.CodigoOrdenDeconstruccion, 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 = ("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,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,88 @@ | ||
# 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"] | ||
moves = 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 | ||
and x.move_line_ids | ||
) | ||
if len(move_raw.product_id) == 0: | ||
raise ValidationError( | ||
_("Production of empty cylinder 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 cylinder (%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 | ||
) | ||
moves |= move_raw | ||
return moves | ||
|
||
|
||
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="Production", | ||
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_cylinder"), | ||
("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,70 @@ | ||
# 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 CodigoOrdenDeconstruccion(self, record): | ||
unbuild = self.env["mrp.unbuild"].search( | ||
[("mo_id", "=", record.odoo_id.id), ("state", "=", "done")] | ||
) | ||
if len(unbuild) > 1: | ||
raise ValidationError( | ||
_("The production %s has more than one unbuild. %s") | ||
% (record.name, unbuild.mapped("name")) | ||
) | ||
return {"CodigoOrdenDeconstruccion": unbuild.name or None} | ||
|
||
@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() | ||
mrp_type_map = { | ||
"cylinder": ("CodigoCilindro", "LoteCilindro"), | ||
"valve": ("CodigoValvula", "LoteValvula"), | ||
} | ||
res = {} | ||
for move_raw in move_raws: | ||
mrp_type = move_raw.product_id.mrp_type | ||
if mrp_type not in mrp_type_map: | ||
raise ValidationError(_("Invalid product type: %s") % mrp_type) | ||
default_code = move_raw.product_id.default_code | ||
if not default_code: | ||
raise ValidationError( | ||
_("Internal Reference not set in product: %s") | ||
% move_raw.product_id.name | ||
) | ||
lot = move_raw.move_line_ids.lot_id | ||
if not lot: | ||
raise ValidationError( | ||
_("Serial Number not set in product: %s") % move_raw.product_id.name | ||
) | ||
code_key, lot_key = mrp_type_map[mrp_type] | ||
res[code_key] = default_code | ||
res[lot_key] = lot.name | ||
return res |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if "t" is already in mssql_type_map, ValidationError if is