From fccfa83de8c1d7d4c42b9e43e0b41cc8d31d0722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Jan 2010 11:03:14 +0100 Subject: [PATCH] Use PySON --- service.py | 6 ++++-- work.py | 16 ++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/service.py b/service.py index 688ee4fd50..76136cef36 100644 --- a/service.py +++ b/service.py @@ -3,13 +3,14 @@ "Service" from trytond.model import ModelView, ModelSQL, fields from trytond.model.cacheable import Cacheable +from trytond.pyson import Eval class Employee(ModelSQL, ModelView, Cacheable): _name = 'company.employee' cost_price = fields.Function('get_cost_price', string='Cost Price', - type='numeric', digits="(16, currency_digits)", + type='numeric', digits=(16, Eval('currency_digits', 2)), depends=['currency_digits'], help="Hourly cost price for this Employee") cost_prices = fields.One2Many('company.employee_cost_price', 'employee', @@ -99,7 +100,8 @@ class EmployeeCostPrice(ModelSQL, ModelView): _description = __doc__ _rec_name = 'date' date = fields.Date('Date', required=True, select=1) - cost_price = fields.Numeric('Cost Price', digits="(16, currency_digits)", + cost_price = fields.Numeric('Cost Price', + digits=(16, Eval('currency_digits', 2)), required=True, depends=['currency_digits'], help="Hourly cost price") employee = fields.Many2One('company.employee', 'Employee') diff --git a/work.py b/work.py index f66694c023..3570101a46 100644 --- a/work.py +++ b/work.py @@ -2,6 +2,7 @@ #this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields +from trytond.pyson import Not, Equal, Eval from decimal import Decimal class TimesheetLine(ModelSQL, ModelView): @@ -33,20 +34,23 @@ class Work(ModelSQL, ModelView): product = fields.Many2One('product.product', 'Product', states={ - 'invisible': "type!= 'task'" + 'invisible': Not(Equal(Eval('type'), 'task')), }, on_change=['product', 'party', 'hours', 'company'], depends=['type', 'party', 'hours', 'company']) - list_price = fields.Numeric('List Price', digits="(16, currency_digits)", + list_price = fields.Numeric('List Price', + digits=(16, Eval('currency_digits', 2)), states={ - 'invisible': "type!= 'task'" + 'invisible': Not(Equal(Eval('type'), 'task')), }, depends=['type', 'currency_digits']) revenue = fields.Function('get_revenue', type='numeric', - string='Revenue', digits="(16, currency_digits)", + string='Revenue', + digits=(16, Eval('currency_digits', 2)), states={ - 'invisible': "type!= 'project'" + 'invisible': Not(Equal(Eval('type'), 'project')), }, depends=['type', 'currency_digits']) cost = fields.Function('get_cost', string='Cost', type='numeric', - digits="(16, currency_digits)", depends=['currency_digits']) + digits=(16, Eval('currency_digits', 2)), + depends=['currency_digits']) currency_digits = fields.Function('get_currency_digits', type='integer', string='Currency Digits', on_change_with=['company'])