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