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