From 2d4235feef2d4db95bbc51f111948849d41a4c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 4 Aug 2011 16:57:18 +0200 Subject: [PATCH] Add test for depends --- product.py | 22 +++++++++++----------- tests/test_account_product.py | 8 +++++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/product.py b/product.py index 119482e92c..0576ce6402 100644 --- a/product.py +++ b/product.py @@ -1,7 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields -from trytond.pyson import Not, Eval, Bool, Or +from trytond.pyson import Not, Eval, Bool, Or, Get from trytond.backend import TableHandler from trytond.transaction import Transaction from trytond.pool import Pool @@ -13,18 +13,18 @@ class Category(ModelSQL, ModelView): account_expense = fields.Property(fields.Many2One('account.account', 'Account Expense', domain=[ ('kind', '=', 'expense'), - ('company', '=', Eval('company')), + ('company', '=', Get(Eval('context', {}), 'company')), ], on_change=['account_expense'], states={ - 'invisible': Not(Bool(Eval('company'))), + 'invisible': Not(Bool(Get(Eval('context', {}), 'company'))), })) account_revenue = fields.Property(fields.Many2One( 'account.account', 'Account Revenue', domain=[ ('kind', '=', 'revenue'), - ('company', '=', Eval('company')), + ('company', '=', Get(Eval('context', {}), 'company')), ], on_change=['account_revenue'], states={ - 'invisible': Not(Bool(Eval('company'))), + 'invisible': Not(Bool(Get(Eval('context', {}), 'company'))), })) customer_taxes = fields.Many2Many('product.category-customer-account.tax', 'category', 'tax', 'Customer Taxes', domain=[('parent', '=', False)]) @@ -110,20 +110,20 @@ class Template(ModelSQL, ModelView): account_expense = fields.Property(fields.Many2One('account.account', 'Account Expense', domain=[ ('kind', '=', 'expense'), - ('company', '=', Eval('company')), + ('company', '=', Get(Eval('context', {}), 'company')), ], on_change=['account_expense'], states={ - 'invisible': Or(Not(Bool(Eval('company'))), + 'invisible': Or(Not(Bool(Get(Eval('context', {}), 'company'))), Bool(Eval('account_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['account_category'])) account_revenue = fields.Property(fields.Many2One('account.account', 'Account Revenue', domain=[ ('kind', '=', 'revenue'), - ('company', '=', Eval('company')), + ('company', '=', Get(Eval('context', {}), 'company')), ], on_change=['account_revenue'], states={ - 'invisible': Or(Not(Bool(Eval('company'))), + 'invisible': Or(Not(Bool(Get(Eval('context', {}), 'company'))), Bool(Eval('account_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['account_category'])) @@ -136,13 +136,13 @@ class Template(ModelSQL, ModelView): customer_taxes = fields.Many2Many('product.template-customer-account.tax', 'product', 'tax', 'Customer Taxes', domain=[('parent', '=', False)], states={ - 'invisible': Or(Not(Bool(Eval('company'))), + 'invisible': Or(Not(Bool(Get(Eval('context', {}), 'company'))), Bool(Eval('taxes_category'))), }, depends=['taxes_category']) supplier_taxes = fields.Many2Many('product.template-supplier-account.tax', 'product', 'tax', 'Supplier Taxes', domain=[('parent', '=', False)], states={ - 'invisible': Or(Not(Bool(Eval('company'))), + 'invisible': Or(Not(Bool(Get(Eval('context', {}), 'company'))), Bool(Eval('taxes_category'))), }, depends=['taxes_category']) customer_taxes_used = fields.Function(fields.One2Many('account.tax', None, diff --git a/tests/test_account_product.py b/tests/test_account_product.py index 74229facc0..6562f44ac0 100644 --- a/tests/test_account_product.py +++ b/tests/test_account_product.py @@ -10,7 +10,7 @@ if os.path.isdir(DIR): import unittest import trytond.tests.test_tryton -from trytond.tests.test_tryton import test_view +from trytond.tests.test_tryton import test_view, test_depends class AccountProductTestCase(unittest.TestCase): @@ -27,6 +27,12 @@ class AccountProductTestCase(unittest.TestCase): ''' test_view('account_product') + def test0006depends(self): + ''' + Test depends. + ''' + test_depends() + def suite(): suite = trytond.tests.test_tryton.suite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase(