From 1af8ebcaac36dacd625e4145e8d8e5921a0afc8f Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Mon, 10 Jan 2011 16:24:23 +0530 Subject: [PATCH 1/5] [REF]account:Add constraint on account.account and account.account.template for type bzr revid: ara@tinyerp.com-20110110105423-g2mvc5yr1lje0vwd --- addons/account/account.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index a5090d3226a..3be44fd8edf 100755 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -418,9 +418,17 @@ class account_account(osv.osv): c_ids = s_ids ids = child_ids return True + + def _check_type(self, cr, uid, ids, context=None): + type = self.browse(cr, uid, ids, context=context) + for t in type: + if t.parent_id.type != 'view' and t.parent_id: + return False + return True _constraints = [ - (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']) + (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']), + (_check_type, 'Internal type of parent account must be view.', ['parent_id']), ] _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') @@ -2295,9 +2303,18 @@ class account_account_template(osv.osv): 'nocreate': False, } + def _check_type(self, cr, uid, ids, context=None): + type = self.browse(cr, uid, ids, context=context) + for t in type: + if t.parent_id.type != 'view' and t.parent_id: + return False + return True + _check_recursion = check_cycle _constraints = [ - (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']) + (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']), + (_check_type, 'Internal type of parent account template must be view.', ['parent_id']), + ] From 1058ae9c8b3cf4b189fb30d72415dd88a1d8801c Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Tue, 11 Jan 2011 10:49:52 +0530 Subject: [PATCH 2/5] [REF]account:Add constraint on account.account and account.account.template for type bzr revid: ara@tinyerp.com-20110111051952-8fscm1f9ia1mq2gh --- addons/account/account.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 3be44fd8edf..f5c9392723d 100755 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -428,7 +428,7 @@ class account_account(osv.osv): _constraints = [ (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']), - (_check_type, 'Internal type of parent account must be view.', ['parent_id']), + (_check_type, 'You cannot create a account! \nMake sure if the account has children it should be type "View"! ', ['parent_id']), ] _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') @@ -2313,7 +2313,7 @@ class account_account_template(osv.osv): _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']), - (_check_type, 'Internal type of parent account template must be view.', ['parent_id']), + (_check_type, 'You cannot create a account template! \nMake sure if the account template has children it should be type "View"! ', ['parent_id']), ] From f338b963b896847e40a8a561c513dd69be84527d Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Tue, 11 Jan 2011 11:33:18 +0530 Subject: [PATCH 3/5] [REF]account:improve variable name bzr revid: ara@tinyerp.com-20110111060318-ctjohf91qc6xotfe --- addons/account/account.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index f5c9392723d..bc8c2a0f775 100755 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -420,15 +420,17 @@ class account_account(osv.osv): return True def _check_type(self, cr, uid, ids, context=None): - type = self.browse(cr, uid, ids, context=context) - for t in type: - if t.parent_id.type != 'view' and t.parent_id: + if context is None: + context = {} + accounts = self.browse(cr, uid, ids, context=context) + for account in accounts: + if account.parent_id.type != 'view' and account.parent_id: return False return True _constraints = [ (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']), - (_check_type, 'You cannot create a account! \nMake sure if the account has children it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account! \nMake sure if the account has parent it should be type "View"! ', ['parent_id']), ] _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') @@ -2304,16 +2306,18 @@ class account_account_template(osv.osv): } def _check_type(self, cr, uid, ids, context=None): - type = self.browse(cr, uid, ids, context=context) - for t in type: - if t.parent_id.type != 'view' and t.parent_id: + if context is None: + context = {} + accounts = self.browse(cr, uid, ids, context=context) + for account in accounts: + if account.parent_id.type != 'view' and account.parent_id: return False return True _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']), - (_check_type, 'You cannot create a account template! \nMake sure if the account template has children it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account template! \nMake sure if the account template has parent it should be type "View"! ', ['parent_id']), ] From facafa1ed9067319fc03f64585ab0b154724c746 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Tue, 11 Jan 2011 12:06:42 +0530 Subject: [PATCH 4/5] [REF]account:improve message string bzr revid: ara@tinyerp.com-20110111063642-ywa2c47xgqtkxazp --- addons/account/account.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index bc8c2a0f775..5b102ed0cb0 100755 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -424,13 +424,13 @@ class account_account(osv.osv): context = {} accounts = self.browse(cr, uid, ids, context=context) for account in accounts: - if account.parent_id.type != 'view' and account.parent_id: + if account.parent_id and account.parent_id.type != 'view': return False return True _constraints = [ (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']), - (_check_type, 'You cannot create a account! \nMake sure if the account has parent it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account! \nMake sure if the account has parent then it should be type "View"! ', ['parent_id']), ] _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') @@ -2310,14 +2310,14 @@ class account_account_template(osv.osv): context = {} accounts = self.browse(cr, uid, ids, context=context) for account in accounts: - if account.parent_id.type != 'view' and account.parent_id: + if account.parent_id and account.parent_id.type != 'view': return False return True _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']), - (_check_type, 'You cannot create a account template! \nMake sure if the account template has parent it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account template! \nMake sure if the account template has parent then it should be type "View"! ', ['parent_id']), ] From 23bae8a2c4fdbb029c6dab23657e052b03768897 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Tue, 11 Jan 2011 15:02:52 +0530 Subject: [PATCH 5/5] [REF]account:improve constraint bzr revid: ara@tinyerp.com-20110111093252-eponfkyerjhzhgys --- addons/account/account.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 5b102ed0cb0..53d0df1df5a 100755 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -422,15 +422,15 @@ class account_account(osv.osv): def _check_type(self, cr, uid, ids, context=None): if context is None: context = {} - accounts = self.browse(cr, uid, ids, context=context) + accounts = self.browse(cr, uid, ids, context=context) for account in accounts: - if account.parent_id and account.parent_id.type != 'view': + if account.child_id and account.type != 'view': return False return True _constraints = [ (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id']), - (_check_type, 'You cannot create a account! \nMake sure if the account has parent then it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account! \nMake sure if the account has children then it should be type "View"! ', ['type']), ] _sql_constraints = [ ('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !') @@ -2310,14 +2310,14 @@ class account_account_template(osv.osv): context = {} accounts = self.browse(cr, uid, ids, context=context) for account in accounts: - if account.parent_id and account.parent_id.type != 'view': + if account.parent_id and account.parent_id.type != 'view': return False return True _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id']), - (_check_type, 'You cannot create a account template! \nMake sure if the account template has parent then it should be type "View"! ', ['parent_id']), + (_check_type, 'You cannot create a account template! \nMake sure if the account template has parent then it should be type "View"! ', ['type']), ]