From 311643b66bcc9348be29ae335bc8f360fe662739 Mon Sep 17 00:00:00 2001 From: Guillem Barba Date: Mon, 30 Apr 2012 11:38:55 +0200 Subject: [PATCH] [IMP] nan_mrp_without_internal_picking: removed code and workflow transitions redefinition not required and formatting --- __openerp__.py | 24 ++++++------- mrp.py | 94 ++++++++++++++++++++++++++++---------------------- mrp_view.xml | 27 +++++++-------- workflow.xml | 24 +++---------- 4 files changed, 81 insertions(+), 88 deletions(-) diff --git a/__openerp__.py b/__openerp__.py index 53b8965..d66d05e 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -27,27 +27,27 @@ # ############################################################################## - { - "name" : "MRP Without internal Picking", - "version" : "0.1", - "author" : "NaN Projectes de Programari Lliure S.L.", - "category" : "Generic Modules/Production", + "name": "MRP Without internal Picking", + "version": "0.1", + "author": "NaN Projectes de Programari Lliure S.L.", + "category": "Generic Modules/Production", "website": "http://www.nan-tic.com", - "description": """ + "description": """ """, - "depends" : [ - "mrp" + "depends": [ + "mrp", ], - "init_xml" : [], - "update_xml" : [ + "init_xml": [], + "update_xml": [ "workflow.xml", - "mrp_view.xml", + "mrp_view.xml", ], - "demo_xml" : [], + "demo_xml": [], "test": [ ], "active": False, "installable": True, } + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/mrp.py b/mrp.py index c73ef8c..f588368 100644 --- a/mrp.py +++ b/mrp.py @@ -27,19 +27,18 @@ # ############################################################################## -from osv import osv, fields +from osv import osv import netsvc from tools.translate import _ from datetime import datetime class mrp_production(osv.osv): - _inherit = 'mrp.production' + # mrp.production def action_confirm(self, cr, uid, ids): proc_ids = [] - seq_obj = self.pool.get('ir.sequence') move_obj = self.pool.get('stock.move') proc_obj = self.pool.get('procurement.order') wf_service = netsvc.LocalService("workflow") @@ -47,21 +46,24 @@ class mrp_production(osv.osv): if not production.product_lines: self.action_compute(cr, uid, [production.id]) production = self.browse(cr, uid, [production.id])[0] - routing_loc = None + routing_loc = None - if production.bom_id.routing_id and production.bom_id.routing_id.location_id: - routing_loc = production.bom_id.routing_id.location_id - routing_loc = routing_loc.id + if (production.bom_id.routing_id and + production.bom_id.routing_id.location_id): + routing_loc = production.bom_id.routing_id.location_id.id - source = production.product_id.product_tmpl_id.property_stock_production.id + source = production.product_id.product_tmpl_id\ + .property_stock_production.id data = { - 'name':'PROD:' + production.name, + 'name': 'PROD:' + production.name, 'date': production.date_planned, 'product_id': production.product_id.id, 'product_qty': production.product_qty, 'product_uom': production.product_uom.id, - 'product_uos_qty': production.product_uos and production.product_uos_qty or False, - 'product_uos': production.product_uos and production.product_uos.id or False, + 'product_uos_qty': (production.product_uos and + production.product_uos_qty or False), + 'product_uos': (production.product_uos and + production.product_uos.id or False), 'location_id': source, 'location_dest_id': production.location_dest_id.id, 'move_dest_id': production.move_prod_id.id, @@ -70,76 +72,84 @@ class mrp_production(osv.osv): } res_final_id = move_obj.create(cr, uid, data) - self.write(cr, uid, [production.id], {'move_created_ids': [(6, 0, [res_final_id])]}) + self.write(cr, uid, [production.id], { + 'move_created_ids': [(6, 0, [res_final_id])], + }) moves = [] for line in production.product_lines: - move_id = False - newdate = production.date_planned if line.product_id.type in ('product', 'consu'): res_dest_id = move_obj.create(cr, uid, { - 'name':'PROD:' + production.name, + 'name': 'PROD:' + production.name, 'date': production.date_planned, 'product_id': line.product_id.id, 'product_qty': line.product_qty, 'product_uom': line.product_uom.id, - 'product_uos_qty': line.product_uos and line.product_uos_qty or False, - 'product_uos': line.product_uos and line.product_uos.id or False, - 'location_id': routing_loc or production.location_src_id.id, + 'product_uos_qty': (line.product_uos and + line.product_uos_qty or False), + 'product_uos': (line.product_uos and + line.product_uos.id or False), + 'location_id': (routing_loc or + production.location_src_id.id), 'location_dest_id': source, 'move_dest_id': res_final_id, 'state': 'waiting', 'company_id': production.company_id.id, }) moves.append(res_dest_id) - proc_vals = self._calc_procurement_vals_from_product_line(cr, + proc_vals = self._calc_procurement_vals_from_product_line(cr, uid, line, res_dest_id) proc_id = proc_obj.create(cr, uid, proc_vals) - wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) + wf_service.trg_validate(uid, 'procurement.order', proc_id, + 'button_confirm', cr) proc_ids.append(proc_id) - self.write(cr, uid, [production.id], {'move_lines': [(6,0,moves)], 'state':'confirmed'}) - message = _("Manufacturing order '%s' is scheduled for the %s.") % ( - production.name, - datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y'), - ) + self.write(cr, uid, [production.id], { + 'move_lines': [(6, 0, moves)], + 'state': 'confirmed', + }) + message = _("Manufacturing order '%s' is scheduled for the %s.") \ + % ( + production.name, + datetime.strptime(production.date_planned, + '%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y'), + ) self.log(cr, uid, production.id, message) return True - + + # mrp.production def check_availability(self, cr, uid, ids, context=None): - for prod in self.browse(cr, uid, ids ): - for move in prod.move_lines: + for prod in self.browse(cr, uid, ids): + for move in prod.move_lines: if move.state != 'assigned': return False return True - - + + # mrp.production def check_production(self, cr, uid, ids, context=None): - wf_service = netsvc.LocalService("workflow") - for prod in self.browse(cr, uid, ids ): + for prod in self.browse(cr, uid, ids): for move in prod.move_lines: for procurement in move.procurements: wf_service.trg_validate(uid, 'procurement.order', procurement.id, 'button_check', cr) - self.check_availability(cr, uid, ids, context) - + if self.check_availability(cr, uid, ids, context): self.action_ready(cr, uid, ids) return True - + + # mrp.production def force_production(self, cr, uid, ids, *args): """ Assigns products. @param *args: Arguments @return: True """ - move_ids=[] - for prod in self.browse(cr, uid, ids ): - move_ids += [x.id for x in prod.move_lines if x.state in ['confirmed','waiting']] - + move_ids = [] + for prod in self.browse(cr, uid, ids): + move_ids += [x.id for x in prod.move_lines + if x.state in ('confirmed', 'waiting')] + self.pool.get('stock.move').force_assign(cr, uid, move_ids) - self.action_ready(cr, uid, ids) + self.action_ready(cr, uid, ids) return True - mrp_production() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/mrp_view.xml b/mrp_view.xml index a56eae9..3a3bcca 100644 --- a/mrp_view.xml +++ b/mrp_view.xml @@ -1,18 +1,17 @@ - + + + mrp.production.wo_internal_picking.form + mrp.production + form + + + + + - - mrp.production.check.form - mrp.production - form - - - - - - - + diff --git a/workflow.xml b/workflow.xml index 9f42d9d..ed632ce 100644 --- a/workflow.xml +++ b/workflow.xml @@ -1,34 +1,18 @@ - - - + + picking function action_confirm() - - - - - - button_confirm - test_if_product() - + check_availability() - - - + \ No newline at end of file