From feef8dc53b8057208ee6579bc131c7b4d23b2366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Jan 2010 10:58:31 +0100 Subject: [PATCH] Use PySON --- account.py | 29 +++++++++++++++-------------- line.py | 17 +++++++++-------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/account.py b/account.py index 91c7224e23..d378b91ab7 100644 --- a/account.py +++ b/account.py @@ -3,6 +3,7 @@ "Account" from trytond.model import ModelView, ModelSQL, fields from trytond.wizard import Wizard +from trytond.pyson import Equal, Eval, Not, PYSONEncoder from decimal import Decimal import copy @@ -27,22 +28,22 @@ class Account(ModelSQL, ModelView): root = fields.Many2One('analytic_account.account', 'Root', select=2, domain=[('parent', '=', False)], states={ - 'invisible': "type == 'root'", - 'required': "type != 'root'", + 'invisible': Equal(Eval('type'), 'root'), + 'required': Not(Equal(Eval('type'), 'root')), }) parent = fields.Many2One('analytic_account.account', 'Parent', select=2, - domain=["('parent', 'child_of', root)"], + domain=[('parent', 'child_of', Eval('root'))], states={ - 'invisible': "type == 'root'", - 'required': "type != 'root'", + 'invisible': Equal(Eval('type'), 'root'), + 'required': Not(Equal(Eval('type'), 'root')), }) childs = fields.One2Many('analytic_account.account', 'parent', 'Children') - balance = fields.Function('get_balance', digits="(16, currency_digits)", - string='Balance') - credit = fields.Function('get_credit_debit', digits="(16, currency_digits)", - string='Credit') - debit = fields.Function('get_credit_debit', digits="(16, currency_digits)", - string='Debit') + balance = fields.Function('get_balance', + digits=(16, Eval('currency_digits', 1)), string='Balance') + credit = fields.Function('get_credit_debit', + digits=(16, Eval('currency_digits', 2)), string='Credit') + debit = fields.Function('get_credit_debit', + digits=(16, Eval('currency_digits', 2)), string='Debit') state = fields.Selection([ ('draft', 'Draft'), ('opened', 'Opened'), @@ -54,7 +55,7 @@ class Account(ModelSQL, ModelView): ('credit-debit', 'Credit - Debit'), ], 'Display Balance', required=True) mandatory = fields.Boolean('Mandatory', states={ - 'invisible': "type != 'root'", + 'invisible': Not(Equal(Eval('type'), 'root')), }) def __init__(self): @@ -353,9 +354,9 @@ class OpenChartAccount(Wizard): model_data = model_data_obj.browse(cursor, user, model_data_ids[0], context=context) res = act_window_obj.read(cursor, user, model_data.db_id, context=context) - res['context'] = str({ + res['pyson_context'] = PYSONEncoder().encode({ 'start_date': data['form']['start_date'], - 'end_date': data['form']['end_date'] + 'end_date': data['form']['end_date'], }) return res diff --git a/line.py b/line.py index 90fb44539b..66bb9eae37 100644 --- a/line.py +++ b/line.py @@ -1,9 +1,10 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level -#of this repository contains the full copyright notices and license terms. +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. "Line" from trytond.model import ModelView, ModelSQL, fields from trytond.wizard import Wizard from trytond.backend import TableHandler +from trytond.pyson import Eval, PYSONEncoder import time @@ -13,9 +14,9 @@ class Line(ModelSQL, ModelView): _description = __doc__ name = fields.Char('Name', required=True) - debit = fields.Numeric('Debit', digits="(16, currency_digits)", + debit = fields.Numeric('Debit', digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']) - credit = fields.Numeric('Credit', digits="(16, currency_digits)", + credit = fields.Numeric('Credit', digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']) currency = fields.Function('get_currency', type='many2one', relation='currency.currency', string='Currency', @@ -161,15 +162,15 @@ class OpenAccount(Wizard): model_data = model_data_obj.browse(cursor, user, model_data_ids[0], context=context) res = act_window_obj.read(cursor, user, model_data.db_id, context=context) - res['domain'] = [ + res['pyson_domain'] = [ ('account', '=', data['id']), ] if context.get('start_date'): - res['domain'].append(('date', '>=', context['start_date'])) + res['pyson_domain'].append(('date', '>=', context['start_date'])) if context.get('end_date'): - res['domain'].append(('date', '<=', context['end_date'])) - res['domain'] = str(res['domain']) + res['pyson_domain'].append(('date', '<=', context['end_date'])) + res['pyson_domain'] = PYSONEncoder().encode(res['pyson_domain']) return res OpenAccount()