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