[MERGE] merge bzr saas-4 web branch
[odoo/odoo.git] / addons / mrp_operations / mrp_operations.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import fields
23 from openerp.osv import osv
24 import time
25 from datetime import datetime
26 from openerp.tools.translate import _
27
28 #----------------------------------------------------------
29 # Work Centers
30 #----------------------------------------------------------
31 # capacity_hour : capacity per hour. default: 1.0.
32 #          Eg: If 5 concurrent operations at one time: capacity = 5 (because 5 employees)
33 # unit_per_cycle : how many units are produced for one cycle
34
35 class stock_move(osv.osv):
36     _inherit = 'stock.move'
37     _columns = {
38         'move_dest_id_lines': fields.one2many('stock.move','move_dest_id', 'Children Moves')
39     }
40
41     def copy(self, cr, uid, id, default=None, context=None):
42         if default is None:
43             default = {}
44         default.update({
45             'move_dest_id_lines': [],
46         })
47         return super(stock_move, self).copy(cr, uid, id, default, context)
48
49
50 class mrp_production_workcenter_line(osv.osv):
51
52     def _get_date_end(self, cr, uid, ids, field_name, arg, context=None):
53         """ Finds ending date.
54         @return: Dictionary of values.
55         """
56         ops = self.browse(cr, uid, ids, context=context)
57         date_and_hours_by_cal = [(op.date_planned, op.hour, op.workcenter_id.calendar_id.id) for op in ops if op.date_planned]
58
59         intervals = self.pool.get('resource.calendar').interval_get_multi(cr, uid, date_and_hours_by_cal)
60
61         res = {}
62         for op in ops:
63             res[op.id] = False
64             if op.date_planned:
65                 i = intervals.get((op.date_planned, op.hour, op.workcenter_id.calendar_id.id))
66                 if i:
67                     res[op.id] = i[-1][1].strftime('%Y-%m-%d %H:%M:%S')
68                 else:
69                     res[op.id] = op.date_planned
70         return res
71
72     def onchange_production_id(self, cr, uid, ids, production_id, context=None):
73         if not production_id:
74             return {}
75         production = self.pool.get('mrp.production').browse(cr, uid, production_id, context=None)
76         result = {
77             'product': production.product_id.id,
78             'qty': production.product_qty,
79             'uom': production.product_uom.id,
80         }
81         return {'value': result}
82
83     _inherit = 'mrp.production.workcenter.line'
84     _order = "sequence, date_planned"
85
86     _columns = {
87        'state': fields.selection([('draft','Draft'),('cancel','Cancelled'),('pause','Pending'),('startworking', 'In Progress'),('done','Finished')],'Status', readonly=True,
88                                  help="* When a work order is created it is set in 'Draft' status.\n" \
89                                        "* When user sets work order in start mode that time it will be set in 'In Progress' status.\n" \
90                                        "* When work order is in running mode, during that time if user wants to stop or to make changes in order then can set in 'Pending' status.\n" \
91                                        "* When the user cancels the work order it will be set in 'Canceled' status.\n" \
92                                        "* When order is completely processed that time it is set in 'Finished' status."),
93        'date_planned': fields.datetime('Scheduled Date', select=True),
94        'date_planned_end': fields.function(_get_date_end, string='End Date', type='datetime'),
95        'date_start': fields.datetime('Start Date'),
96        'date_finished': fields.datetime('End Date'),
97        'delay': fields.float('Working Hours',help="The elapsed time between operation start and stop in this Work Center",readonly=True),
98        'production_state':fields.related('production_id','state',
99             type='selection',
100             selection=[('draft','Draft'),('picking_except', 'Picking Exception'),('confirmed','Waiting Goods'),('ready','Ready to Produce'),('in_production','In Production'),('cancel','Canceled'),('done','Done')],
101             string='Production Status', readonly=True),
102        'product':fields.related('production_id','product_id',type='many2one',relation='product.product',string='Product',
103             readonly=True),
104        'qty':fields.related('production_id','product_qty',type='float',string='Qty',readonly=True, store=True),
105        'uom':fields.related('production_id','product_uom',type='many2one',relation='product.uom',string='Unit of Measure',readonly=True),
106     }
107
108     _defaults = {
109         'state': 'draft',
110         'delay': 0.0,
111         'production_state': 'draft'
112     }
113
114     def modify_production_order_state(self, cr, uid, ids, action):
115         """ Modifies production order state if work order state is changed.
116         @param action: Action to perform.
117         @return: Nothing
118         """
119         prod_obj_pool = self.pool.get('mrp.production')
120         oper_obj = self.browse(cr, uid, ids)[0]
121         prod_obj = oper_obj.production_id
122         if action == 'start':
123                if prod_obj.state =='confirmed':
124                    prod_obj_pool.force_production(cr, uid, [prod_obj.id])
125                    prod_obj_pool.signal_button_produce(cr, uid, [prod_obj.id])
126                elif prod_obj.state =='ready':
127                    prod_obj_pool.signal_button_produce(cr, uid, [prod_obj.id])
128                elif prod_obj.state =='in_production':
129                    return
130                else:
131                    raise osv.except_osv(_('Error!'),_('Manufacturing order cannot be started in state "%s"!') % (prod_obj.state,))
132         else:
133             oper_ids = self.search(cr,uid,[('production_id','=',prod_obj.id)])
134             obj = self.browse(cr,uid,oper_ids)
135             flag = True
136             for line in obj:
137                 if line.state != 'done':
138                      flag = False
139             if flag:
140                 for production in prod_obj_pool.browse(cr, uid, [prod_obj.id], context= None):
141                     if production.move_lines or production.move_created_ids:
142                         prod_obj_pool.action_produce(cr,uid, production.id, production.product_qty, 'consume_produce', context = None)
143                 prod_obj_pool.signal_button_produce_done(cr, uid, [oper_obj.production_id.id])
144         return
145
146     def write(self, cr, uid, ids, vals, context=None, update=True):
147         result = super(mrp_production_workcenter_line, self).write(cr, uid, ids, vals, context=context)
148         prod_obj = self.pool.get('mrp.production')
149         if vals.get('date_planned', False) and update:
150             for prod in self.browse(cr, uid, ids, context=context):
151                 if prod.production_id.workcenter_lines:
152                     dstart = min(vals['date_planned'], prod.production_id.workcenter_lines[0]['date_planned'])
153                     prod_obj.write(cr, uid, [prod.production_id.id], {'date_start':dstart}, context=context, mini=False)
154         return result
155
156     def action_draft(self, cr, uid, ids, context=None):
157         """ Sets state to draft.
158         @return: True
159         """
160         return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
161
162     def action_start_working(self, cr, uid, ids, context=None):
163         """ Sets state to start working and writes starting date.
164         @return: True
165         """
166         self.modify_production_order_state(cr, uid, ids, 'start')
167         self.write(cr, uid, ids, {'state':'startworking', 'date_start': time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
168         return True
169
170     def action_done(self, cr, uid, ids, context=None):
171         """ Sets state to done, writes finish date and calculates delay.
172         @return: True
173         """
174         delay = 0.0
175         date_now = time.strftime('%Y-%m-%d %H:%M:%S')
176         obj_line = self.browse(cr, uid, ids[0])
177
178         date_start = datetime.strptime(obj_line.date_start,'%Y-%m-%d %H:%M:%S')
179         date_finished = datetime.strptime(date_now,'%Y-%m-%d %H:%M:%S')
180         delay += (date_finished-date_start).days * 24
181         delay += (date_finished-date_start).seconds / float(60*60)
182
183         self.write(cr, uid, ids, {'state':'done', 'date_finished': date_now,'delay':delay}, context=context)
184         self.modify_production_order_state(cr,uid,ids,'done')
185         return True
186
187     def action_cancel(self, cr, uid, ids, context=None):
188         """ Sets state to cancel.
189         @return: True
190         """
191         return self.write(cr, uid, ids, {'state':'cancel'}, context=context)
192
193     def action_pause(self, cr, uid, ids, context=None):
194         """ Sets state to pause.
195         @return: True
196         """
197         return self.write(cr, uid, ids, {'state':'pause'}, context=context)
198
199     def action_resume(self, cr, uid, ids, context=None):
200         """ Sets state to startworking.
201         @return: True
202         """
203         return self.write(cr, uid, ids, {'state':'startworking'}, context=context)
204
205
206 class mrp_production(osv.osv):
207     _inherit = 'mrp.production'
208     _columns = {
209         'allow_reorder': fields.boolean('Free Serialisation', help="Check this to be able to move independently all production orders, without moving dependent ones."),
210     }
211
212     def _production_date_end(self, cr, uid, ids, prop, unknow_none, context=None):
213         """ Calculates planned end date of production order.
214         @return: Dictionary of values
215         """
216         result = {}
217         for prod in self.browse(cr, uid, ids, context=context):
218             result[prod.id] = prod.date_planned
219             for line in prod.workcenter_lines:
220                 result[prod.id] = max(line.date_planned_end, result[prod.id])
221         return result
222
223     def action_production_end(self, cr, uid, ids):
224         """ Finishes work order if production order is done.
225         @return: Super method
226         """
227         obj = self.browse(cr, uid, ids)[0]
228         workcenter_pool = self.pool.get('mrp.production.workcenter.line')
229         for workcenter_line in obj.workcenter_lines:
230             if workcenter_line.state == 'draft':
231                 workcenter_pool.signal_button_start_working(cr, uid, [workcenter_line.id])
232             workcenter_pool.signal_button_done(cr, uid, [workcenter_line.id])
233         return super(mrp_production,self).action_production_end(cr, uid, ids)
234
235     def action_in_production(self, cr, uid, ids):
236         """ Changes state to In Production and writes starting date.
237         @return: True
238         """
239         workcenter_pool = self.pool.get('mrp.production.workcenter.line')
240         for prod in self.browse(cr, uid, ids):
241             if prod.workcenter_lines:
242                 workcenter_pool.signal_button_start_working(cr, uid, [prod.workcenter_lines[0].id])
243         return super(mrp_production,self).action_in_production(cr, uid, ids)
244     
245     def action_cancel(self, cr, uid, ids, context=None):
246         """ Cancels work order if production order is canceled.
247         @return: Super method
248         """
249         workcenter_pool = self.pool.get('mrp.production.workcenter.line')
250         obj = self.browse(cr, uid, ids,context=context)[0]
251         for workcenter_line in obj.workcenter_lines:
252             workcenter_pool.signal_button_cancel(cr, uid, [workcenter_line.id])
253         return super(mrp_production,self).action_cancel(cr,uid,ids,context=context)
254
255     def _compute_planned_workcenter(self, cr, uid, ids, context=None, mini=False):
256         """ Computes planned and finished dates for work order.
257         @return: Calculated date
258         """
259         dt_end = datetime.now()
260         if context is None:
261             context = {}
262         for po in self.browse(cr, uid, ids, context=context):
263             dt_end = datetime.strptime(po.date_planned, '%Y-%m-%d %H:%M:%S')
264             if not po.date_start:
265                 self.write(cr, uid, [po.id], {
266                     'date_start': po.date_planned
267                 }, context=context, update=False)
268             old = None
269             for wci in range(len(po.workcenter_lines)):
270                 wc  = po.workcenter_lines[wci]
271                 if (old is None) or (wc.sequence>old):
272                     dt = dt_end
273                 if context.get('__last_update'):
274                     del context['__last_update']
275                 if (wc.date_planned < dt.strftime('%Y-%m-%d %H:%M:%S')) or mini:
276                     self.pool.get('mrp.production.workcenter.line').write(cr, uid, [wc.id],  {
277                         'date_planned': dt.strftime('%Y-%m-%d %H:%M:%S')
278                     }, context=context, update=False)
279                     i = self.pool.get('resource.calendar').interval_get(
280                         cr,
281                         uid,
282                         wc.workcenter_id.calendar_id and wc.workcenter_id.calendar_id.id or False,
283                         dt,
284                         wc.hour or 0.0
285                     )
286                     if i:
287                         dt_end = max(dt_end, i[-1][1])
288                 else:
289                     dt_end = datetime.strptime(wc.date_planned_end, '%Y-%m-%d %H:%M:%S')
290
291                 old = wc.sequence or 0
292             super(mrp_production, self).write(cr, uid, [po.id], {
293                 'date_finished': dt_end
294             })
295         return dt_end
296
297     def _move_pass(self, cr, uid, ids, context=None):
298         """ Calculates start date for stock moves finding interval from resource calendar.
299         @return: True
300         """
301         for po in self.browse(cr, uid, ids, context=context):
302             if po.allow_reorder:
303                 continue
304             todo = po.move_lines
305             dt = datetime.strptime(po.date_start,'%Y-%m-%d %H:%M:%S')
306             while todo:
307                 l = todo.pop(0)
308                 if l.state in ('done','cancel','draft'):
309                     continue
310                 todo += l.move_dest_id_lines
311                 if l.production_id and (l.production_id.date_finished > dt):
312                     if l.production_id.state not in ('done','cancel'):
313                         for wc in l.production_id.workcenter_lines:
314                             i = self.pool.get('resource.calendar').interval_min_get(
315                                 cr,
316                                 uid,
317                                 wc.workcenter_id.calendar_id.id or False,
318                                 dt, wc.hour or 0.0
319                             )
320                             dt = i[0][0]
321                         if l.production_id.date_start > dt.strftime('%Y-%m-%d %H:%M:%S'):
322                             self.write(cr, uid, [l.production_id.id], {'date_start':dt.strftime('%Y-%m-%d %H:%M:%S')}, mini=True)
323         return True
324
325     def _move_futur(self, cr, uid, ids, context=None):
326         """ Calculates start date for stock moves.
327         @return: True
328         """
329         for po in self.browse(cr, uid, ids, context=context):
330             if po.allow_reorder:
331                 continue
332             for line in po.move_created_ids:
333                 l = line
334                 while l.move_dest_id:
335                     l = l.move_dest_id
336                     if l.state in ('done','cancel','draft'):
337                         break
338                     if l.production_id.state in ('done','cancel'):
339                         break
340                     if l.production_id and (l.production_id.date_start < po.date_finished):
341                         self.write(cr, uid, [l.production_id.id], {'date_start': po.date_finished})
342                         break
343         return True
344
345
346     def write(self, cr, uid, ids, vals, context=None, update=True, mini=True):
347         direction = {}
348         if vals.get('date_start', False):
349             for po in self.browse(cr, uid, ids, context=context):
350                 direction[po.id] = cmp(po.date_start, vals.get('date_start', False))
351         result = super(mrp_production, self).write(cr, uid, ids, vals, context=context)
352         if (vals.get('workcenter_lines', False) or vals.get('date_start', False)) and update:
353             self._compute_planned_workcenter(cr, uid, ids, context=context, mini=mini)
354         for d in direction:
355             if direction[d] == 1:
356                 # the production order has been moved to the passed
357                 self._move_pass(cr, uid, [d], context=context)
358                 pass
359             elif direction[d] == -1:
360                 self._move_futur(cr, uid, [d], context=context)
361                 # the production order has been moved to the future
362                 pass
363         return result
364
365     def action_compute(self, cr, uid, ids, properties=None, context=None):
366         """ Computes bills of material of a product and planned date of work order.
367         @param properties: List containing dictionaries of properties.
368         @return: No. of products.
369         """
370         result = super(mrp_production, self).action_compute(cr, uid, ids, properties=properties, context=context)
371         self._compute_planned_workcenter(cr, uid, ids, context=context)
372         return result
373
374
375 class mrp_operations_operation_code(osv.osv):
376     _name="mrp_operations.operation.code"
377     _columns={
378         'name': fields.char('Operation Name',size=64, required=True),
379         'code': fields.char('Code', size=16, required=True),
380         'start_stop': fields.selection([('start','Start'),('pause','Pause'),('resume','Resume'),('cancel','Cancelled'),('done','Done')], 'Status', required=True),
381     }
382
383 class mrp_operations_operation(osv.osv):
384     _name="mrp_operations.operation"
385
386     def _order_date_search_production(self, cr, uid, ids, context=None):
387         """ Finds operations for a production order.
388         @return: List of ids
389         """
390         operation_ids = self.pool.get('mrp_operations.operation').search(cr, uid, [('production_id','=',ids[0])], context=context)
391         return operation_ids
392
393     def _get_order_date(self, cr, uid, ids, field_name, arg, context=None):
394         """ Calculates planned date for an operation.
395         @return: Dictionary of values
396         """
397         res={}
398         operation_obj = self.browse(cr, uid, ids, context=context)
399         for operation in operation_obj:
400                 res[operation.id] = operation.production_id.date_planned
401         return res
402
403     def calc_delay(self, cr, uid, vals):
404         """ Calculates delay of work order.
405         @return: Delay
406         """
407         code_lst = []
408         time_lst = []
409
410         code_ids = self.pool.get('mrp_operations.operation.code').search(cr, uid, [('id','=',vals['code_id'])])
411         code = self.pool.get('mrp_operations.operation.code').browse(cr, uid, code_ids)[0]
412
413         oper_ids = self.search(cr,uid,[('production_id','=',vals['production_id']),('workcenter_id','=',vals['workcenter_id'])])
414         oper_objs = self.browse(cr,uid,oper_ids)
415
416         for oper in oper_objs:
417             code_lst.append(oper.code_id.start_stop)
418             time_lst.append(oper.date_start)
419
420         code_lst.append(code.start_stop)
421         time_lst.append(vals['date_start'])
422         diff = 0
423         for i in range(0,len(code_lst)):
424             if code_lst[i] == 'pause' or code_lst[i] == 'done' or code_lst[i] == 'cancel':
425                 if not i: continue
426                 if code_lst[i-1] not in ('resume','start'):
427                    continue
428                 a = datetime.strptime(time_lst[i-1],'%Y-%m-%d %H:%M:%S')
429                 b = datetime.strptime(time_lst[i],'%Y-%m-%d %H:%M:%S')
430                 diff += (b-a).days * 24
431                 diff += (b-a).seconds / float(60*60)
432         return diff
433
434     def check_operation(self, cr, uid, vals):
435         """ Finds which operation is called ie. start, pause, done, cancel.
436         @param vals: Dictionary of values.
437         @return: True or False
438         """
439         code_ids=self.pool.get('mrp_operations.operation.code').search(cr,uid,[('id','=',vals['code_id'])])
440         code=self.pool.get('mrp_operations.operation.code').browse(cr,uid,code_ids)[0]
441         code_lst = []
442         oper_ids=self.search(cr,uid,[('production_id','=',vals['production_id']),('workcenter_id','=',vals['workcenter_id'])])
443         oper_objs=self.browse(cr,uid,oper_ids)
444
445         if not oper_objs:
446             if code.start_stop!='start':
447                 raise osv.except_osv(_('Sorry!'),_('Operation is not started yet!'))
448                 return False
449         else:
450             for oper in oper_objs:
451                  code_lst.append(oper.code_id.start_stop)
452             if code.start_stop=='start':
453                     if 'start' in code_lst:
454                         raise osv.except_osv(_('Sorry!'),_('Operation has already started! You can either Pause/Finish/Cancel the operation.'))
455                         return False
456             if code.start_stop=='pause':
457                     if  code_lst[len(code_lst)-1]!='resume' and code_lst[len(code_lst)-1]!='start':
458                         raise osv.except_osv(_('Error!'),_('In order to Pause the operation, it must be in the Start or Resume state!'))
459                         return False
460             if code.start_stop=='resume':
461                 if code_lst[len(code_lst)-1]!='pause':
462                    raise osv.except_osv(_('Error!'),_('In order to Resume the operation, it must be in the Pause state!'))
463                    return False
464
465             if code.start_stop=='done':
466                if code_lst[len(code_lst)-1]!='start' and code_lst[len(code_lst)-1]!='resume':
467                   raise osv.except_osv(_('Sorry!'),_('In order to Finish the operation, it must be in the Start or Resume state!'))
468                   return False
469                if 'cancel' in code_lst:
470                   raise osv.except_osv(_('Sorry!'),_('Operation is Already Cancelled!'))
471                   return False
472             if code.start_stop=='cancel':
473                if  not 'start' in code_lst :
474                    raise osv.except_osv(_('Error!'),_('No operation to cancel.'))
475                    return False
476                if 'done' in code_lst:
477                   raise osv.except_osv(_('Error!'),_('Operation is already finished!'))
478                   return False
479         return True
480
481     def write(self, cr, uid, ids, vals, context=None):
482         oper_objs = self.browse(cr, uid, ids, context=context)[0]
483         vals['production_id']=oper_objs.production_id.id
484         vals['workcenter_id']=oper_objs.workcenter_id.id
485
486         if 'code_id' in vals:
487             self.check_operation(cr, uid, vals)
488
489         if 'date_start' in vals:
490             vals['date_start']=vals['date_start']
491             vals['code_id']=oper_objs.code_id.id
492             delay=self.calc_delay(cr, uid, vals)
493             wc_op_id=self.pool.get('mrp.production.workcenter.line').search(cr,uid,[('workcenter_id','=',vals['workcenter_id']),('production_id','=',vals['production_id'])])
494             self.pool.get('mrp.production.workcenter.line').write(cr,uid,wc_op_id,{'delay':delay})
495
496         return super(mrp_operations_operation, self).write(cr, uid, ids, vals, context=context)
497
498     def create(self, cr, uid, vals, context=None):
499         workcenter_pool = self.pool.get('mrp.production.workcenter.line')
500         code_ids=self.pool.get('mrp_operations.operation.code').search(cr,uid,[('id','=',vals['code_id'])])
501         code=self.pool.get('mrp_operations.operation.code').browse(cr, uid, code_ids, context=context)[0]
502         wc_op_id=workcenter_pool.search(cr,uid,[('workcenter_id','=',vals['workcenter_id']),('production_id','=',vals['production_id'])])
503         if code.start_stop in ('start','done','pause','cancel','resume'):
504             if not wc_op_id:
505                 production_obj=self.pool.get('mrp.production').browse(cr, uid, vals['production_id'], context=context)
506                 wc_op_id.append(workcenter_pool.create(cr,uid,{'production_id':vals['production_id'],'name':production_obj.product_id.name,'workcenter_id':vals['workcenter_id']}))
507             if code.start_stop=='start':
508                 workcenter_pool.action_start_working(cr,uid,wc_op_id)
509                 workcenter_pool.signal_button_start_working(cr, uid, [wc_op_id[0]])
510
511             if code.start_stop=='done':
512                 workcenter_pool.action_done(cr,uid,wc_op_id)
513                 workcenter_pool.signal_button_done(cr, uid, [wc_op_id[0]])
514                 self.pool.get('mrp.production').write(cr,uid,vals['production_id'],{'date_finished':datetime.now().strftime('%Y-%m-%d %H:%M:%S')})
515
516             if code.start_stop=='pause':
517                 workcenter_pool.action_pause(cr,uid,wc_op_id)
518                 workcenter_pool.signal_button_pause(cr, uid, [wc_op_id[0]])
519
520             if code.start_stop=='resume':
521                 workcenter_pool.action_resume(cr,uid,wc_op_id)
522                 workcenter_pool.signal_button_resume(cr, uid, [wc_op_id[0]])
523
524             if code.start_stop=='cancel':
525                 workcenter_pool.action_cancel(cr,uid,wc_op_id)
526                 workcenter_pool.signal_button_cancel(cr, uid, [wc_op_id[0]])
527
528         if not self.check_operation(cr, uid, vals):
529             return
530         delay=self.calc_delay(cr, uid, vals)
531         line_vals = {}
532         line_vals['delay'] = delay
533         if vals.get('date_start',False):
534             if code.start_stop == 'done':
535                 line_vals['date_finished'] = vals['date_start']
536             elif code.start_stop == 'start':
537                 line_vals['date_start'] = vals['date_start']
538
539         self.pool.get('mrp.production.workcenter.line').write(cr, uid, wc_op_id, line_vals, context=context)
540
541         return super(mrp_operations_operation, self).create(cr, uid, vals, context=context)
542
543     def initialize_workflow_instance(self, cr, uid, context=None):
544         mrp_production_workcenter_line = self.pool.get('mrp.production.workcenter.line')
545         line_ids = mrp_production_workcenter_line.search(cr, uid, [], context=context)
546         mrp_production_workcenter_line.create_workflow(cr, uid, line_ids)
547         return True
548
549     _columns={
550         'production_id':fields.many2one('mrp.production','Production',required=True),
551         'workcenter_id':fields.many2one('mrp.workcenter','Work Center',required=True),
552         'code_id':fields.many2one('mrp_operations.operation.code','Code',required=True),
553         'date_start': fields.datetime('Start Date'),
554         'date_finished': fields.datetime('End Date'),
555         'order_date': fields.function(_get_order_date,string='Order Date',type='date',store={'mrp.production':(_order_date_search_production,['date_planned'], 10)}),
556         }
557     _defaults={
558         'date_start': lambda *a:datetime.now().strftime('%Y-%m-%d %H:%M:%S')
559     }
560
561 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
562