From 1219b56bccefa332786057a7590bb71405fd381b Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 31 Mar 2015 15:32:24 +0200 Subject: [PATCH] [FIX] project: change view according to project uom The working time unit can either be hours or days. In case of days, should replace the references to hours in the view to days. In case of days, use float field instead of float_time. Using the string 'Hours' as a way to determine the unit is too weak as: 1. it does not work in other language than english 2. if the unit is renamed (*cough* 1626eca *cough*), it will fail as well Using the object with context to compare strings in the user language. lp:1080191, opw 595397 --- addons/project/project.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index debeefa9f1f..080e72f7678 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -898,18 +898,23 @@ class task(base_stage, osv.osv): def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): users_obj = self.pool.get('res.users') if context is None: context = {} - # read uom as admin to avoid access rights issues, e.g. for portal/share users, - # this should be safe (no context passed to avoid side-effects) - obj_tm = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).company_id.project_time_mode_id - tm = obj_tm and obj_tm.name or 'Hours' res = super(task, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu) - if tm in ['Hours','Hour']: + # read uom as admin to avoid access rights issues, e.g. for portal/share users, + # this should be safe (no context passed to avoid side-effects) + obj_tm = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).company_id.project_time_mode_id + try: + # using get_object to get translation value + uom_hour = self.pool['ir.model.data'].get_object(cr, uid, 'product', 'product_uom_hour', context=context) + except ValueError: + uom_hour = False + if not obj_tm or not uom_hour or obj_tm.id == uom_hour.id: return res eview = etree.fromstring(res['arch']) + # if the project_time_mode_id is not in hours (so in days), display it as a float field def _check_rec(eview): if eview.attrib.get('widget','') == 'float_time': eview.set('widget','float') @@ -921,9 +926,13 @@ class task(base_stage, osv.osv): res['arch'] = etree.tostring(eview) + # replace reference of 'Hours' to 'Day(s)' for f in res['fields']: + # TODO this NOT work in different language than english + # the field 'Initially Planned Hours' should be replaced by 'Initially Planned Days' + # but string 'Initially Planned Days' is not available in translation if 'Hours' in res['fields'][f]['string']: - res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours',tm) + res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours', obj_tm.name) return res # ----------------------------------------