diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 62e64dbbd59..15d034e0010 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -452,6 +452,25 @@ class mrp_production(osv.osv): result[mrp_production.id] = done / mrp_production.product_qty * 100 return result + def _moves_assigned(self, cr, uid, ids, name, arg, context=None): + """ Test whether all the consume lines are assigned """ + res = True + for production in self.browse(cr, uid, ids, context=context): + states = [x.state != 'assigned' for x in production.move_lines if x] + if any(states) or len(states) == 0: + return False + return res + + + def _mrp_from_move(self, cr, uid, ids, context=None): + """ Return mrp""" + res = [] + for move in self.browse(cr, uid, ids, context=context): + res += self.pool.get("mrp.production").search(cr, uid, [('move_lines', 'in', move.id)], context=context) + return res + + + _columns = { 'name': fields.char('Reference', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), 'origin': fields.char('Source Document', size=64, readonly=True, states={'draft': [('readonly', False)]}, @@ -510,6 +529,8 @@ class mrp_production(osv.osv): 'cycle_total': fields.function(_production_calc, type='float', string='Total Cycles', multi='workorder', store=True), 'user_id':fields.many2one('res.users', 'Responsible'), 'company_id': fields.many2one('res.company','Company',required=True), + 'ready_production': fields.function(_moves_assigned, type='boolean', store={'stock.move': (_mrp_from_move, ['state'], 10)}), + } _defaults = { 'priority': lambda *a: '1', @@ -554,7 +575,6 @@ class mrp_production(osv.osv): 'move_created_ids2' : [], 'product_lines' : [], 'move_prod_id' : False, - 'picking_id' : False }) return super(mrp_production, self).copy(cr, uid, id, default, context) diff --git a/addons/mrp/mrp_workflow.xml b/addons/mrp/mrp_workflow.xml index 23119bf9490..388dd9039b3 100644 --- a/addons/mrp/mrp_workflow.xml +++ b/addons/mrp/mrp_workflow.xml @@ -43,7 +43,7 @@ True function - action_production_end() + action_production_end() done @@ -70,7 +70,7 @@ - picking_id and picking_id.state=='done' + ready_production diff --git a/addons/project_mrp/project_mrp.py b/addons/project_mrp/project_mrp.py index 08227a8dae0..f9aea33f2fb 100644 --- a/addons/project_mrp/project_mrp.py +++ b/addons/project_mrp/project_mrp.py @@ -123,9 +123,9 @@ class product_product(osv.osv): class sale_order(osv.osv): _inherit = 'sale.order' - def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None): + def _prepare_order_line_procurement(self, cr, uid, order, line, group_id=False, context=None): proc_data = super(sale_order, self)._prepare_order_line_procurement(cr, - uid, order, line, move_id, date_planned, context=context) + uid, order, line, group_id = group_id, context=context) proc_data['sale_line_id'] = line.id return proc_data