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