Skip to content

Commit

Permalink
[IMP] Added the migrated module
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Nov 13, 2024
1 parent df18822 commit 7dba18b
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 101 deletions.
4 changes: 3 additions & 1 deletion plm_auto_engcode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
Expand All @@ -19,4 +20,5 @@
#
##############################################################################
from . import models

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
15 changes: 6 additions & 9 deletions plm_auto_engcode/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
Expand All @@ -20,21 +21,17 @@
##############################################################################
{
"name": "PLM Automatic Engineering Code",
"version": "18.0.0.1",
"version": "18.0.1.0.0",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
"sequence": 15,
"summary": "",
"images": [],
"summary": """
This Module Create Part Number for PLM Automatic Engineering Code
""",
"license": "AGPL-3",
"depends": ["plm"],
"data": [
"views/ir_sequence.xml",
"views/product_category.xml"
],
"demo": [],
"test": [],
"data": ["data/ir_sequence.xml", "views/product_category.xml"],
"installable": True,
"application": False,
"auto_install": False,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>

<data noupdate="1">
<odoo>
<data noupdate="0">

This comment has been minimized.

Copy link
@OmniaGit

OmniaGit Nov 13, 2024

Owner

leave the no update as one
The use case will be that the customer change the prefix for any reason and we do not want that during the update the user lose the change

<record id="seq_plm_eng_code" model="ir.sequence">
<field name="name">PLM Engineering Code Sequence</field>
<field name="code">plm.eng.code</field>
<field name="prefix">EG-</field>
<field name="padding">5</field>
</record>
</data>

</openerp>
</odoo>
3 changes: 2 additions & 1 deletion plm_auto_engcode/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
Expand Down
19 changes: 6 additions & 13 deletions plm_auto_engcode/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@
# along with this prograIf not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
'''
"""
Created on 30 Oct 2022
@author: mboscolo
'''
"""
from odoo import models, fields


from odoo import models
from odoo import fields
from odoo import api
from odoo import _
from odoo.exceptions import UserError
import logging


class ProductCategory(models.Model):
_inherit = 'product.category'
plm_code_sequence = fields.Many2one('ir.sequence',
string='Part Number sequence')
_inherit = "product.category"

plm_code_sequence = fields.Many2one("ir.sequence", string="Part Number sequence")
54 changes: 28 additions & 26 deletions plm_auto_engcode/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
Expand All @@ -23,39 +24,40 @@
@author: Daniel Smerghetto
"""
from odoo import models
from odoo import fields
from odoo import api
from odoo import _, api, fields, models

from odoo import _
from odoo.exceptions import UserError
import logging

class pProductProduct(models.Model):
_inherit = 'product.product'
class ProductProduct(models.Model):
_inherit = "product.product"

@api.onchange("categ_id")
def onchange_categ_id(self):
"""
An onchange method to update the 'engineering_code'
"""
product = self.product_tmpl_id
if self.engineering_code_editable:
self.product_tmpl_id.engineering_code = self.product_tmpl_id._getNewCode()

product.engineering_code = product._getNewCode()


class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"

def _getNewCode(self):
if self.env.context.get('odooPLM', False):
"""
A custom method to generate the sequence for 'engineering_code'.
"""
if self.env.context.get("odooPLM", False):
if self.categ_id and self.categ_id.plm_code_sequence:
return self.categ_id.plm_code_sequence.next_by_id()
return self.env['ir.sequence'].next_by_code('plm.eng.code')
return self.env["ir.sequence"].next_by_code("plm.eng.code")
return False

@api.onchange("categ_id")
def onchange_categ_id(self):
if self.engineering_code_editable:
self.engineering_code = self._getNewCode()

engineering_code = fields.Char(_('Part Number'),
index=True,
default = _getNewCode,
help=_("This is engineering reference to manage a different P/N from item Name."),
size=64)

engineering_code = fields.Char(
_("Part Number"),
index=True,
help=_(
"This is engineering reference to manage a different P/N from item Name."
),
size=64,
)
1 change: 0 additions & 1 deletion plm_auto_engcode/views/product_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
</field>
</record>
</odoo>

3 changes: 2 additions & 1 deletion plm_auto_internalref/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
Expand Down
12 changes: 6 additions & 6 deletions plm_auto_internalref/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
Expand All @@ -20,18 +21,17 @@
##############################################################################
{
"name": "PLM Auto Internal Reference",
"version": "18.0.0.1",
"version": "18.0.1.0.0",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"summary": """This Module Create Auto Internal Reference""",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
"sequence": 15,
"license": "AGPL-3",
"summary": "Allow to compute boms due to date",
"images": [],
"depends": ["plm"],
"data": ["views/product_product.xml"],
"demo": [],
"test": [],
"data": [
"views/product_product.xml"
],
"installable": True,
"application": False,
"auto_install": False,
Expand Down
1 change: 1 addition & 0 deletions plm_auto_internalref/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Your own solutions
Expand Down
42 changes: 20 additions & 22 deletions plm_auto_internalref/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Your own solutions
Expand Down Expand Up @@ -31,45 +32,44 @@


class ProductProductExtension(models.Model):
_name = 'product.product'
_inherit = 'product.product'
_name = "product.product"
_inherit = "product.product"

@api.model_create_multi
def create(self, vals):
for val_dict in vals:
new_default_code = self.computeDefaultCode(val_dict)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
val_dict['default_code'] = new_default_code
logging.info("OdooPLM: Default Code set to %s " % (new_default_code))
val_dict["default_code"] = new_default_code
return super().create(vals)

@property
def getDefaultCodeTemplate(self):
return "%s_%s"

def computeDefaultCode(self,
vals={},
objBrowse=None):

def computeDefaultCode(self, vals={}, objBrowse=None):
"""
Function to be overloaded for changing the inetrnal referense computation
:vals dict like with all the value that be updated
:objBrowse product.product or product.template in case of write operation
"""

out = False
in_revision = self.env.context.get('new_revision', False)
engineering_code = vals.get('engineering_code', '')
engineering_revision = vals.get('engineering_revision', 0)
default_code = vals.get('default_code')
if objBrowse: #suppose write operation
in_revision = self.env.context.get("new_revision", False)
engineering_code = vals.get("engineering_code", "")
engineering_revision = vals.get("engineering_revision", 0)
default_code = vals.get("default_code")
if objBrowse: # suppose write operation
if not engineering_code:
engineering_code = objBrowse.engineering_code
if not engineering_revision:
engineering_revision = objBrowse.engineering_revision
if not default_code:
default_code = objBrowse.default_code
if in_revision and engineering_code and engineering_code != '-':
default_code = objBrowse.default_code
if in_revision and engineering_code and engineering_code != "-":
out = self.getDefaultCodeTemplate % (engineering_code, engineering_revision)
if engineering_code and not default_code and engineering_code != '-':
if engineering_code and not default_code and engineering_code != "-":
out = self.getDefaultCodeTemplate % (engineering_code, engineering_revision)
if default_code == out:
return False
Expand All @@ -78,11 +78,9 @@ def computeDefaultCode(self,
def write(self, vals):
ret = False
for product in self:
new_default_code = product.computeDefaultCode(vals,
product)
new_default_code = product.computeDefaultCode(vals, product)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
vals['default_code'] = new_default_code
logging.info("OdooPLM: Default Code set to %s " % (new_default_code))
vals["default_code"] = new_default_code
ret = super(models.Model, product).write(vals)
return ret

26 changes: 12 additions & 14 deletions plm_auto_internalref/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,35 @@
#
##############################################################################

'''
"""
Created on 9 Dec 2016
@author: Daniel Smerghetto
'''
"""

from odoo import models
from odoo import api
import logging
from odoo import api, models


class ProductTemplateExtension(models.Model):
_name = 'product.template'
_inherit = 'product.template'
_name = "product.template"
_inherit = "product.template"

@api.model_create_multi
def create(self, vals):
obj_pp = self.env['product.product']
obj_pp = self.env["product.product"]
for val_dict in vals:
new_default_code = obj_pp.computeDefaultCode(val_dict)
if new_default_code:
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
val_dict['default_code'] = new_default_code
logging.info("OdooPLM: Default Code set to %s " % (new_default_code))
val_dict["default_code"] = new_default_code
return super().create(vals)

def write(self, vals):
new_default_code = self.env['product.product'].computeDefaultCode(vals,
self)
if new_default_code :
logging.info('OdooPLM: Default Code set to %s ' % (new_default_code))
vals['default_code'] = new_default_code
new_default_code = self.env["product.product"].computeDefaultCode(vals, self)
if new_default_code:
logging.info("OdooPLM: Default Code set to %s " % (new_default_code))
vals["default_code"] = new_default_code
return super(ProductTemplateExtension, self).write(vals)


Expand Down
2 changes: 0 additions & 2 deletions plm_auto_internalref/views/product_product.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_product_product_search_int_ref" model="ir.ui.view">
<field name="name">product.product.search.int.ref</field>
<field name="model">product.product</field>
Expand All @@ -11,5 +10,4 @@
</field>
</field>
</record>

</odoo>

0 comments on commit 7dba18b

Please sign in to comment.