From 58ee9b99c3e2c93ea5ede53536868a86bdacc43d Mon Sep 17 00:00:00 2001 From: Mitali Patel Date: Mon, 2 May 2016 12:50:24 +0200 Subject: [PATCH] [MOV] mr_byproduct: move and split --- addons/mrp_byproduct/__init__.py | 5 +- addons/mrp_byproduct/__openerp__.py | 4 +- addons/mrp_byproduct/models/__init__.py | 7 ++ addons/mrp_byproduct/models/mrp_bom.py | 14 ++++ .../mrp_production.py} | 72 +------------------ addons/mrp_byproduct/models/mrp_subproduct.py | 47 ++++++++++++ .../mrp_byproduct/{ => models}/stock_move.py | 0 .../mrp_bom_views.xml} | 0 addons/mrp_byproduct/wizard/__init__.py | 4 ++ .../wizard/change_production_qty.py | 21 ++++++ 10 files changed, 99 insertions(+), 75 deletions(-) create mode 100644 addons/mrp_byproduct/models/__init__.py create mode 100644 addons/mrp_byproduct/models/mrp_bom.py rename addons/mrp_byproduct/{mrp_byproduct.py => models/mrp_production.py} (53%) create mode 100644 addons/mrp_byproduct/models/mrp_subproduct.py rename addons/mrp_byproduct/{ => models}/stock_move.py (100%) rename addons/mrp_byproduct/{mrp_byproduct_view.xml => views/mrp_bom_views.xml} (100%) create mode 100644 addons/mrp_byproduct/wizard/__init__.py create mode 100644 addons/mrp_byproduct/wizard/change_production_qty.py diff --git a/addons/mrp_byproduct/__init__.py b/addons/mrp_byproduct/__init__.py index 3e4207dc81c..1331bcbef92 100644 --- a/addons/mrp_byproduct/__init__.py +++ b/addons/mrp_byproduct/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import mrp_byproduct -import stock_move + +import models +import wizard \ No newline at end of file diff --git a/addons/mrp_byproduct/__openerp__.py b/addons/mrp_byproduct/__openerp__.py index 7bfcde7377e..9f63b149b10 100644 --- a/addons/mrp_byproduct/__openerp__.py +++ b/addons/mrp_byproduct/__openerp__.py @@ -23,8 +23,8 @@ With this module: 'website': 'https://www.odoo.com/page/manufacturing', 'depends': ['base', 'mrp'], 'data': [ - 'security/ir.model.access.csv', - 'mrp_byproduct_view.xml' + 'security/ir.model.access.csv', + 'views/mrp_bom_views.xml' ], 'demo': [], 'test': ['test/mrp_byproduct.yml'], diff --git a/addons/mrp_byproduct/models/__init__.py b/addons/mrp_byproduct/models/__init__.py new file mode 100644 index 00000000000..f0e3975bc42 --- /dev/null +++ b/addons/mrp_byproduct/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import mrp_bom +import mrp_production +import mrp_subproduct +import stock_move \ No newline at end of file diff --git a/addons/mrp_byproduct/models/mrp_bom.py b/addons/mrp_byproduct/models/mrp_bom.py new file mode 100644 index 00000000000..610e8d170f9 --- /dev/null +++ b/addons/mrp_byproduct/models/mrp_bom.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import fields, osv + + +class mrp_bom(osv.osv): + _name = 'mrp.bom' + _description = 'Bill of Material' + _inherit='mrp.bom' + + _columns={ + 'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts', copy=True), + } \ No newline at end of file diff --git a/addons/mrp_byproduct/mrp_byproduct.py b/addons/mrp_byproduct/models/mrp_production.py similarity index 53% rename from addons/mrp_byproduct/mrp_byproduct.py rename to addons/mrp_byproduct/models/mrp_production.py index a86f8bf485c..eaecb20d06a 100644 --- a/addons/mrp_byproduct/mrp_byproduct.py +++ b/addons/mrp_byproduct/models/mrp_production.py @@ -1,60 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import fields from openerp.osv import osv -import openerp.addons.decimal_precision as dp -from openerp.tools.translate import _ - -class mrp_subproduct(osv.osv): - _name = 'mrp.subproduct' - _description = 'Byproduct' - _columns={ - 'product_id': fields.many2one('product.product', 'Product', required=True), - 'product_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product Unit of Measure'), required=True), - 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), - 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True, help="Define how the quantity of byproducts will be set on the production orders using this BoM.\ - 'Fixed' depicts a situation where the quantity of created byproduct is always equal to the quantity set on the BoM, regardless of how many are created in the production order.\ - By opposition, 'Variable' means that the quantity will be computed as\ - '(quantity of byproduct set on the BoM / quantity of manufactured product set on the BoM * quantity of manufactured product in the production order.)'"), - 'bom_id': fields.many2one('mrp.bom', 'BoM', ondelete='cascade'), - } - _defaults={ - 'subproduct_type': 'variable', - 'product_qty': lambda *a: 1.0, - } - - def onchange_product_id(self, cr, uid, ids, product_id, context=None): - """ Changes UoM if product_id changes. - @param product_id: Changed product_id - @return: Dictionary of changed values - """ - if product_id: - prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - v = {'product_uom': prod.uom_id.id} - return {'value': v} - return {} - - def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None): - res = {'value':{}} - if not product_uom or not product_id: - return res - product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) - uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context) - if uom.category_id.id != product.uom_id.category_id.id: - res['warning'] = {'title': _('Warning'), 'message': _('The Product Unit of Measure you chose has a different category than in the product form.')} - res['value'].update({'product_uom': product.uom_id.id}) - return res - - -class mrp_bom(osv.osv): - _name = 'mrp.bom' - _description = 'Bill of Material' - _inherit='mrp.bom' - - _columns={ - 'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts', copy=True), - } class mrp_production(osv.osv): @@ -126,21 +73,4 @@ class mrp_production(osv.osv): elif move.subproduct_id.subproduct_type == 'fixed': return move.product_qty, 0 # no subproduct - return super(mrp_production, self)._calculate_produce_line_qty(cr, uid, move, quantity, context=context) - - -class change_production_qty(osv.osv_memory): - _inherit = 'change.production.qty' - - def _update_product_to_produce(self, cr, uid, prod, qty, context=None): - move_lines_obj = self.pool.get('stock.move') - prod_obj = self.pool.get('mrp.production') - for m in prod.move_created_ids: - if m.product_id.id == prod.product_id.id: - move_lines_obj.write(cr, uid, [m.id], {'product_uom_qty': qty}) - else: - for sub_product_line in prod.bom_id.sub_products: - if sub_product_line.product_id.id == m.product_id.id: - factor = prod_obj._get_subproduct_factor(cr, uid, m, context=context) - subproduct_qty = sub_product_line.subproduct_type == 'variable' and qty * factor or sub_product_line.product_qty - move_lines_obj.write(cr, uid, [m.id], {'product_uom_qty': subproduct_qty}) + return super(mrp_production, self)._calculate_produce_line_qty(cr, uid, move, quantity, context=context) \ No newline at end of file diff --git a/addons/mrp_byproduct/models/mrp_subproduct.py b/addons/mrp_byproduct/models/mrp_subproduct.py new file mode 100644 index 00000000000..3978b64c378 --- /dev/null +++ b/addons/mrp_byproduct/models/mrp_subproduct.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import fields +from openerp.osv import osv +import openerp.addons.decimal_precision as dp +from openerp.tools.translate import _ + +class mrp_subproduct(osv.osv): + _name = 'mrp.subproduct' + _description = 'Byproduct' + _columns={ + 'product_id': fields.many2one('product.product', 'Product', required=True), + 'product_qty': fields.float('Product Qty', digits_compute=dp.get_precision('Product Unit of Measure'), required=True), + 'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True), + 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True, help="Define how the quantity of byproducts will be set on the production orders using this BoM.\ + 'Fixed' depicts a situation where the quantity of created byproduct is always equal to the quantity set on the BoM, regardless of how many are created in the production order.\ + By opposition, 'Variable' means that the quantity will be computed as\ + '(quantity of byproduct set on the BoM / quantity of manufactured product set on the BoM * quantity of manufactured product in the production order.)'"), + 'bom_id': fields.many2one('mrp.bom', 'BoM', ondelete='cascade'), + } + _defaults={ + 'subproduct_type': 'variable', + 'product_qty': lambda *a: 1.0, + } + + def onchange_product_id(self, cr, uid, ids, product_id, context=None): + """ Changes UoM if product_id changes. + @param product_id: Changed product_id + @return: Dictionary of changed values + """ + if product_id: + prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + v = {'product_uom': prod.uom_id.id} + return {'value': v} + return {} + + def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None): + res = {'value':{}} + if not product_uom or not product_id: + return res + product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context) + if uom.category_id.id != product.uom_id.category_id.id: + res['warning'] = {'title': _('Warning'), 'message': _('The Product Unit of Measure you chose has a different category than in the product form.')} + res['value'].update({'product_uom': product.uom_id.id}) + return res diff --git a/addons/mrp_byproduct/stock_move.py b/addons/mrp_byproduct/models/stock_move.py similarity index 100% rename from addons/mrp_byproduct/stock_move.py rename to addons/mrp_byproduct/models/stock_move.py diff --git a/addons/mrp_byproduct/mrp_byproduct_view.xml b/addons/mrp_byproduct/views/mrp_bom_views.xml similarity index 100% rename from addons/mrp_byproduct/mrp_byproduct_view.xml rename to addons/mrp_byproduct/views/mrp_bom_views.xml diff --git a/addons/mrp_byproduct/wizard/__init__.py b/addons/mrp_byproduct/wizard/__init__.py new file mode 100644 index 00000000000..dd641e61dee --- /dev/null +++ b/addons/mrp_byproduct/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import change_production_qty \ No newline at end of file diff --git a/addons/mrp_byproduct/wizard/change_production_qty.py b/addons/mrp_byproduct/wizard/change_production_qty.py new file mode 100644 index 00000000000..721c6f30b06 --- /dev/null +++ b/addons/mrp_byproduct/wizard/change_production_qty.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import osv + + +class change_production_qty(osv.osv_memory): + _inherit = 'change.production.qty' + + def _update_product_to_produce(self, cr, uid, prod, qty, context=None): + move_lines_obj = self.pool.get('stock.move') + prod_obj = self.pool.get('mrp.production') + for m in prod.move_created_ids: + if m.product_id.id == prod.product_id.id: + move_lines_obj.write(cr, uid, [m.id], {'product_uom_qty': qty}) + else: + for sub_product_line in prod.bom_id.sub_products: + if sub_product_line.product_id.id == m.product_id.id: + factor = prod_obj._get_subproduct_factor(cr, uid, m, context=context) + subproduct_qty = sub_product_line.subproduct_type == 'variable' and qty * factor or sub_product_line.product_qty + move_lines_obj.write(cr, uid, [m.id], {'product_uom_qty': subproduct_qty}) \ No newline at end of file