[IMP]:
authorpap (openerp) <pap@tinyerp.co.in>
Mon, 18 Jan 2010 13:44:53 +0000 (19:14 +0530)
committerpap (openerp) <pap@tinyerp.co.in>
Mon, 18 Jan 2010 13:44:53 +0000 (19:14 +0530)
1) start_date < end_date in leave form
2) remove duplicate fields from mrp.workcenter
3) remove recursion in project phases, start_date < end_date
start_date < end_date in project.task and project.project

bzr revid: pap@tinyerp.co.in-20100118134453-uptuohuxvyqhizfq

addons/mrp/mrp.py
addons/mrp/mrp_view.xml
addons/project/project.py
addons/project/project_view.xml
addons/project_long_term/project.py
addons/resource/resource.py

index 726d5a3..c3a272f 100644 (file)
@@ -42,7 +42,7 @@ class mrp_workcenter(osv.osv):
     _description = 'Work Center'
     _inherits = {'resource.resource':"resource_id"}
     _columns = {
-        'name': fields.char('Work Center Name', size=64, required=True),
+#        'name': fields.char('Work Center Name', size=64, required=True),
         'note': fields.text('Description', help="Description of the workcenter. Explain here what's a cycle according to this workcenter."),
         'capacity_per_cycle': fields.float('Capacity per Cycle', help="Number of operations this workcenter can do in parallel. If this workcenter represents a team of 5 workers, the capacity per cycle is 5."),
         'time_cycle': fields.float('Time for 1 cycle (hour)', help="Time in hours for doing one cycle."),
@@ -56,7 +56,8 @@ class mrp_workcenter(osv.osv):
             help="Complete this only if you want automatic analytic accounting entries on production orders."),
         'costs_journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal'),
         'costs_general_account_id': fields.many2one('account.account', 'General Account', domain=[('type','<>','view')]),
-        'company_id': fields.many2one('res.company','Company',required=True),
+#        'company_id': fields.many2one('res.company','Company',required=True),
+       'resource_id': fields.many2one('resource.resource','Resource',ondelete='cascade'),
     }
     _defaults = {
         'capacity_per_cycle': lambda *a: 1.0,
index 7c567ef..0e7ff6d 100644 (file)
                     </group>
                     <notebook colspan="4">
                         <page string="Work Center">
-                            <field name="type"/>
+                            <field name="resource_type"/>
                             <field name="calendar_id"/>
                             <separator colspan="4" string="Description"/>
                             <field colspan="4" name="note" nolabel="1"/>
index 95a8c94..89cf75e 100644 (file)
@@ -130,6 +130,16 @@ class project(osv.osv):
 #        'state': lambda *a: 'open',
 #        'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'project.project', context=c)
     }
+    def _check_dates(self, cr, uid, ids):
+         leave = self.read(cr, uid, ids[0],['date_start','date'])
+         if leave['date_start'] and leave['date']:
+             if leave['date_start'] > leave['date']:
+                 return False
+         return True
+
+    _constraints = [
+        (_check_dates, 'Error! project start-date must be lower then project end-date.', ['date_start', 'date'])
+    ]
 
 #    _order = "parent_id,priority,name"
 #    _constraints = [
@@ -221,6 +231,32 @@ class task(osv.osv):
     _description = "Tasks"
     _date_name = "date_start"
 
+#    def compute_date(self,cr,uid):
+#        project_id = self.pool.get('project.project').search(cr,uid,[])
+#        for i in range(len(project_id)):
+#            task_ids = self.pool.get('project.task').search(cr,uid,[('project_id','=',project_id[i])])
+#            if task_ids:
+#                task_obj = self.pool.get('project.task').browse(cr,uid,task_ids)
+#                task_1 = task_obj[0]
+#                task_1.date_start = self.pool.get('project.project').browse(cr,uid,project_id[i]).date_start
+##                print '1st Date Start::::',task_1.date_start,type(task_1.date_start)
+#                dt = mx.DateTime.strptime(task_1.date_start,"%Y-%m-%d").strftime("%Y-%m-%d")
+##                print 'Hours:::::',task_1.planned_hours
+##                print 'Date',dt
+#                def Project_1():
+#                   title = "New Project"
+#                   start = dt
+#
+#                   def task1():
+#                       start = dt
+#                       effort = task_1.planned_hours
+#                       title = "Task 1"
+##                project_1 = BalancedProject(Project_1)
+##                print 'Title::::::',project_1.title
+##                for t in project_1:
+##                    print 'details:::',t.indent_name(), t.start, t.end, t.effort
+
+
     def _str_get(self, task, level=0, border='***', context={}):
         return border+' '+(task.user_id and task.user_id.name.upper() or '')+(level and (': L'+str(level)) or '')+(' - %.1fh / %.1fh'%(task.effective_hours or 0.0,task.planned_hours))+' '+border+'\n'+ \
             border[0]+' '+(task.name or '')+'\n'+ \
@@ -266,14 +302,10 @@ class task(osv.osv):
             if date_start and planned:
                 resource_id = self.pool.get('resource.resource').search(cr,uid,[('user_id','=',res.user_id.id)])
                 resource_obj = self.pool.get('resource.resource').browse(cr,uid,resource_id)[0]
-                print 'Resource Calendar::::',resource_obj.calendar_id.id
                 d = mx.DateTime.strptime(date_start,'%Y-%m-%d %H:%M:%S')
                 hrs = (planned)/(occupation_rate)
-                print 'Hours::::',hrs
                 work_times = self.pool.get('resource.calendar').interval_get(cr, uid, resource_obj.calendar_id.id or False, d, hrs or 0.0, resource_obj.id)
-                print 'Date_end',work_times
                 result['date_end'] = work_times[-1][1].strftime('%Y-%m-%d %H:%M:%S')
-                print 'Date End',result['date_end']
         result['remaining_hours'] = planned-effective
         return {'value':result}
 
index fe6122b..5dffaac 100644 (file)
                             </group>
                         </page>
                         <page groups="base.group_extended" string="Delegations">
-                            <field name="parent_ids"/>
-                            <newline/>
+                               <separator string="Parent Tasks" colspan="4"/>
+                            <field colspan="4" height="150" name="parent_ids" nolabel="1"/>
+                            <separator string="Delegated tasks" colspan="4"/>
                             <field colspan="4" height="150" name="child_ids" nolabel="1" attrs="{'readonly':[('state','!=','draft')]}">
                                 <tree string="Delegated tasks">
                                     <field name="name"/>
                             </field>
                             <field colspan="4" name="history" nolabel="1"/>
                         </page>
+                        
                         <page groups="base.group_extended" string="Extra Info" attrs="{'readonly':[('state','=','done')]}">
                             <group colspan="2" col="2">
                                 <separator string="Planning" colspan="2"/>
index f04e18b..c573426 100644 (file)
@@ -33,32 +33,44 @@ class project_phase(osv.osv):
     _description = "Project Phase"
 
     def _check_recursion(self,cr,uid,ids):
-        level = 100
-        while len(ids):
-            cr.execute('select distinct next_phase_id from project_phase_next_rel where phase_id in ('+','.join(map(str, ids))+')')
-            ids = filter(None, map(lambda x:x[0], cr.fetchall()))
-            next_ids = ids
-            while(next_ids):
-                cr.execute('select distinct prev_phase_id from project_phase_prev_rel where phase_id in ('+','.join(map(str, ids))+')')
-                prev_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
-
-        return True
-
-        while(ids):
-            cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')')
-            child_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
-            c_ids = child_ids
-            if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):
-                return False
-            while len(c_ids):
-                s_ids = self.search(cr, uid, [('parent_id', 'in', c_ids)])
-                if p_id and (p_id in s_ids):
-                    return False
-                c_ids = s_ids
-            ids = child_ids
-        return True
-
-
+         obj_self = self.browse(cr, uid, ids[0])
+         prev_ids = obj_self.previous_phase_ids
+         next_ids = obj_self.next_phase_ids
+         #it should nither be in prev_ids nor in next_ids
+         if (obj_self in prev_ids) or (obj_self in next_ids):
+             return False
+         ids = [id for id in prev_ids if id in next_ids]
+         
+         #both prev_ids and next_ids must be unique
+         if ids:
+             return False
+         #unrelated project
+         
+         prev_ids = [rec.id for rec in prev_ids]
+         next_ids = [rec.id for rec in next_ids]
+
+         #iter prev_ids
+         while prev_ids:
+             cr.execute('select distinct prv_phase_id from project_phase_previous_rel where phase_id in ('+','.join(map(str, prev_ids))+')')
+             prv_phase_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
+             if obj_self.id in prv_phase_ids:
+                 return False
+             ids = [id for id in prv_phase_ids if id in next_ids]
+             if ids:
+                 return False
+             prev_ids = prv_phase_ids
+             
+        #iter next_ids
+         while next_ids:
+             cr.execute('select distinct next_phase_id from project_phase_next_rel where phase_id in ('+','.join(map(str, next_ids))+')')
+             next_phase_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
+             if obj_self.id in next_phase_ids:
+                 return False
+             ids = [id for id in next_phase_ids if id in prev_ids]
+             if ids:
+                 return False
+             next_ids = next_phase_ids
+         return True
 
     _columns = {
         'name': fields.char("Phase Name", size=64, required=True),
@@ -113,6 +125,16 @@ class task(osv.osv):
     _columns = {
         'phase_id': fields.many2one('project.phase', 'Project Phase')
     }
+    def _check_dates(self, cr, uid, ids):
+         leave = self.read(cr, uid, ids[0],['date_start','date_end'])
+         if leave['date_start'] and leave['date_end']:
+             if leave['date_start'] > leave['date_end']:
+                 return False
+         return True
+
+    _constraints = [
+        (_check_dates, 'Error! task start-date must be lower then task end-date.', ['date_start', 'date_end'])
+    ]
 
 task()
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
index dad8aed..7ac36e5 100755 (executable)
@@ -176,7 +176,16 @@ class resource_calendar_leaves(osv.osv):
         'date_from' : fields.datetime('Start Date', required=True),
         'date_to' : fields.datetime('End Date', required=True),
         'resource_id' : fields.many2one("resource.resource", "Resource", help="If empty, this is a generic holiday for the company. If a resource is set, the holiday/leave is only for this resource"),
-
     }
+    def check_dates(self, cr, uid, ids):
+         leave = self.read(cr, uid, ids[0],['date_from','date_to'])
+         if leave['date_from'] and leave['date_to']:
+             if leave['date_from'] > leave['date_to']:
+                 return False
+         return True
+
+    _constraints = [
+        (check_dates, 'Error! leave start-date must be lower then leave end-date.', ['date_from', 'date_to'])
+    ]
 resource_calendar_leaves()
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: