diff --git a/addons/project/company.py b/addons/project/company.py index 18f970118a4e9345a7ff649f1e2ba32ca50343b0..0967d13073758fada259f964d5d10a9d01028805 100644 --- a/addons/project/company.py +++ b/addons/project/company.py @@ -31,13 +31,5 @@ class res_company(osv.osv): "forget to setup the right unit of measure in your employees.", ), } - - def write(self, cr, uid, ids,vals, context={}): - task_ids=self.pool.get('project.task').search(cr, uid, [('state','in',['open', 'pending'])]) - if ('project_time_mode_id' in vals) and task_ids: - raise osv.except_osv(_('Error !'), _('You cannot modify Project Time Unit as there are open or pending tasks created with current time unit.')) - return super(res_company,self).write(cr, uid, ids, vals, context=context) - res_company() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project/project.py b/addons/project/project.py index e60845764f7abe337f5140102ea787eff1985217..254d447b618c0fec5327ed3da9f540c32c25a782 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -712,7 +712,25 @@ class project_work(osv.osv): } _order = "date desc" + def create(self, cr, uid, vals, *args, **kwargs): + if 'hours' in vals and (not vals['hours']): + vals['hours'] = 0.00 + if 'task_id' in vals: + cr.execute('update project_task set remaining_hours=remaining_hours - %s where id=%s', (vals.get('hours',0.0), vals['task_id'])) + return super(project_work,self).create(cr, uid, vals, *args, **kwargs) + + def write(self, cr, uid, ids,vals,context={}): + if 'hours' in vals and (not vals['hours']): + vals['hours'] = 0.00 + if 'hours' in vals: + for work in self.browse(cr, uid, ids, context): + cr.execute('update project_task set remaining_hours=remaining_hours - %s + (%s) where id=%s', (vals.get('hours',0.0), work.hours, work.task_id.id)) + return super(project_work,self).write(cr, uid, ids, vals, context) + def unlink(self, cr, uid, ids, *args, **kwargs): + for work in self.browse(cr, uid, ids): + cr.execute('update project_task set remaining_hours=remaining_hours + %s where id=%s', (work.hours, work.task_id.id)) + return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs) project_work() class account_analytic_account(osv.osv): diff --git a/addons/project/project_demo.xml b/addons/project/project_demo.xml index 34ab831bbe2d2a8e6532011e45fa192e18e2e89a..0c1c386a70048eb8e02c111b4ae68b32db57ce42 100644 --- a/addons/project/project_demo.xml +++ b/addons/project/project_demo.xml @@ -271,7 +271,7 @@ <record id="project_task_116" model="project.task"> <field name="planned_hours">38.0</field> <field name="remaining_hours">38.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field name="user_id" ref="base.user_root"/> <field name="project_id" ref="project_project_22"/> <field name="description">BoM, After sales returns, interventions. Traceability.</field> @@ -280,7 +280,7 @@ <record id="project_task_130" model="project.task"> <field name="planned_hours">16.0</field> <field name="remaining_hours">16.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field model="res.users" name="user_id" search="[('login','=','demo')]"/> <field name="project_id" ref="project_project_23"/> <field name="name">Data importation + Doc</field> @@ -288,7 +288,7 @@ <record id="project_task_131" model="project.task"> <field name="planned_hours">16.0</field> <field name="remaining_hours">16.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field model="res.users" name="user_id" search="[('login','=','demo')]"/> <field name="project_id" ref="project_project_23"/> <field name="name">Modifications asked by the customer.</field> @@ -296,7 +296,7 @@ <record id="project_task_184" model="project.task"> <field name="planned_hours">16.0</field> <field name="remaining_hours">16.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field model="res.users" name="user_id" search="[('login','=','demo')]"/> <field name="priority">0</field> <field name="project_id" ref="project_project_21"/> @@ -306,7 +306,7 @@ <field name="sequence">15</field> <field name="planned_hours">8.0</field> <field name="remaining_hours">8.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field model="res.users" name="user_id" search="[('login','=','demo')]"/> <field name="project_id" ref="project_project_21"/> <field name="name">Internal testing + Software Install</field> @@ -315,7 +315,7 @@ <field name="sequence">17</field> <field name="planned_hours">16.0</field> <field name="remaining_hours">16.0</field> - <field name="type" ref="project_tt_development"/> + <field name="type_id" ref="project_tt_development"/> <field model="res.users" name="user_id" search="[('login','=','demo')]"/> <field name="priority">2</field> <field name="state">open</field> @@ -357,7 +357,6 @@ <field name="project_id" ref="project_project_21"/> <field name="name">MRP; functional layer</field> <field name="state">done</field> - <field eval="time.strftime('%Y-%m-%d 12:12')" name="date_close"/> </record> <record id="project_task_194" model="project.task"> <field name="sequence">30</field> diff --git a/addons/project/test/test_project.yml b/addons/project/test/test_project.yml index bc65ab67f770f01aedaee202b5eb8026b9d79296..8cf8e0afb19e38b822f69a3eb55fd0c7f94f90d5 100644 --- a/addons/project/test/test_project.yml +++ b/addons/project/test/test_project.yml @@ -65,10 +65,6 @@ - !assert {model: project.project, id: project_project_openerptrainingprogramme0, severity: error, string: Project is in open state}: - state == "open" - - - - - Test for different project-states - @@ -109,8 +105,6 @@ - !assert {model: project.project, id: project_project_openerptrainingprogramme0, severity: error, string: Project is in open state}: - state == "open" - - - Test for task work allocation - @@ -140,7 +134,7 @@ - Make a work task entry 'Training on OpenERP modules, models and classes' of 10 hours - - !record {model: project.task, id: project_task_technicaltraining0, context: {'withoutemployee': True}}: + !record {model: project.task, id: project_task_technicaltraining0}: work_ids: - date: '2010-05-31 15:04:22' hours: 10.0 @@ -155,7 +149,7 @@ - Make a work task entry 'Training on OpenERP xml views' of 10 hours - - !record {model: project.task, id: project_task_technicaltraining0, context: {'withoutemployee': True}}: + !record {model: project.task, id: project_task_technicaltraining0}: work_ids: - date: '2010-06-01 15:04:46' hours: 10.0 @@ -170,7 +164,7 @@ - Make a work task entry 'Training on workflows' of 10 hours - - !record {model: project.task, id: project_task_technicaltraining0, context: {'withoutemployee': True}}: + !record {model: project.task, id: project_task_technicaltraining0}: work_ids: - date: '2010-06-02 15:05:24' hours: 10.0 @@ -206,7 +200,7 @@ - Make a work task entry 'Training on reports and wizards' of 10 hours - - !record {model: project.task, id: project_task_technicaltraining0, context: {'withoutemployee': True}}: + !record {model: project.task, id: project_task_technicaltraining0}: work_ids: - date: '2010-05-31 15:08:40' hours: 10.0 @@ -257,7 +251,7 @@ - Make a work task entry 'Training on yml' of 5 hours - - !record {model: project.task, id: project_task_technicaltraining0, context: {'withoutemployee': True}}: + !record {model: project.task, id: project_task_technicaltraining0}: work_ids: - date: '2010-05-31 16:55:27' hours: 5.0