From aad6253cf3b1d9104dd74d7dce4d7bcfc99971b5 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Fri, 11 Mar 2011 17:07:10 +0530 Subject: [PATCH 1/4] [FIX] Account: [6.0]changing company currency breaks analytic account lp bug: https://launchpad.net/bugs/728560 fixed bzr revid: ara@tinyerp.com-20110311113710-wnsy77iv8rlgivj8 --- addons/analytic/analytic.py | 51 +++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index 50a73b3f7d4..bc16dd19348 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -22,6 +22,7 @@ import time from osv import fields, osv +from tools.translate import _ import decimal_precision as dp class account_analytic_account(osv.osv): @@ -120,6 +121,36 @@ class account_analytic_account(osv.osv): return result + def _get_company_currency(self, cr, uid, ids, context=None): + company_obj = self.pool.get('res.company') + analytic_obj = self.pool.get('account.analytic.account') + accounts = [] + for company in company_obj.browse(cr, uid, ids, context=context): + accounts += analytic_obj.search(cr, uid, [('company_id', '=', company.id)]) + return accounts + + def _set_company_currency(self, cr, uid, ids, name, value, arg, context=None): + if type(ids) != type([]): + ids=[ids] + for account in self.browse(cr, uid, ids, context=context): + if not value: + cr.execute("""update account_analytic_account set + currency_id=NULL where id=%s""", (account.id, )) + elif account.company_id.currency_id.id == value: + cr.execute("""update account_analytic_account set + currency_id=%s where id=%s""", (value, account.id, )) + else: + raise osv.except_osv(_('Error !'), _('The currency has to be the same as the currency of the selected company.')) + return True + + def _currency(self, cr, uid, ids, field_name, arg, context=None): + result = {} + for rec in self.browse(cr, uid, ids, context=context): + if not rec.currency_id.id: + result[rec.id] = False + else: + result[rec.id] = rec.company_id.currency_id.id + return result _columns = { 'name': fields.char('Account Name', size=128, required=True), @@ -149,7 +180,11 @@ class account_analytic_account(osv.osv): \n* And finally when all the transactions are over, it can be in \'Close\' state. \ \n* The project can be in either if the states \'Template\' and \'Running\'.\n If it is template then we can make projects based on the template projects. If its in \'Running\' state it is a normal project.\ \n If it is to be reviewed then the state is \'Pending\'.\n When the project is completed the state is set to \'Done\'.'), - 'currency_id': fields.many2one('res.currency', 'Account currency', required=True), + #'currency_id': fields.many2one('res.currency', 'Account currency', required=True), + 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, method=True, + store = { + 'res.company': (_get_company_currency, ['currency_id'], 10), + }, string='Currency', type='many2one', relation='res.currency'), } def _default_company(self, cr, uid, context=None): @@ -173,12 +208,12 @@ class account_analytic_account(osv.osv): 'currency_id': _get_default_currency, } - def check_currency(self, cr, uid, ids, context=None): - obj = self.browse(cr, uid, ids[0], context=context) - if obj.company_id: - if obj.currency_id.id != self.pool.get('res.company').browse(cr, uid, obj.company_id.id, context=context).currency_id.id: - return False - return True +# def check_currency(self, cr, uid, ids, context=None): +# obj = self.browse(cr, uid, ids[0], context=context) +# if obj.company_id: +# if obj.currency_id.id != self.pool.get('res.company').browse(cr, uid, obj.company_id.id, context=context).currency_id.id: +# return False +# return True def check_recursion(self, cr, uid, ids, parent=None): return super(account_analytic_account, self)._check_recursion(cr, uid, ids, parent=parent) @@ -186,7 +221,7 @@ class account_analytic_account(osv.osv): _order = 'date_start desc,parent_id desc,code' _constraints = [ (check_recursion, 'Error! You can not create recursive analytic accounts.', ['parent_id']), - (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']), +# (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']), ] def copy(self, cr, uid, id, default=None, context=None): From 27981af3377a9b62b2d31e20212c79fe6ec08c6a Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Fri, 11 Mar 2011 17:33:35 +0530 Subject: [PATCH 2/4] [FIX] Account: [6.0]changing company currency breaks analytic account bzr revid: ara@tinyerp.com-20110311120335-l1one4lu0fxg8die --- addons/analytic/analytic.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index bc16dd19348..b76071eed7b 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -180,7 +180,6 @@ class account_analytic_account(osv.osv): \n* And finally when all the transactions are over, it can be in \'Close\' state. \ \n* The project can be in either if the states \'Template\' and \'Running\'.\n If it is template then we can make projects based on the template projects. If its in \'Running\' state it is a normal project.\ \n If it is to be reviewed then the state is \'Pending\'.\n When the project is completed the state is set to \'Done\'.'), - #'currency_id': fields.many2one('res.currency', 'Account currency', required=True), 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, method=True, store = { 'res.company': (_get_company_currency, ['currency_id'], 10), @@ -208,20 +207,12 @@ class account_analytic_account(osv.osv): 'currency_id': _get_default_currency, } -# def check_currency(self, cr, uid, ids, context=None): -# obj = self.browse(cr, uid, ids[0], context=context) -# if obj.company_id: -# if obj.currency_id.id != self.pool.get('res.company').browse(cr, uid, obj.company_id.id, context=context).currency_id.id: -# return False -# return True - def check_recursion(self, cr, uid, ids, parent=None): return super(account_analytic_account, self)._check_recursion(cr, uid, ids, parent=parent) _order = 'date_start desc,parent_id desc,code' _constraints = [ (check_recursion, 'Error! You can not create recursive analytic accounts.', ['parent_id']), -# (check_currency, 'Error! The currency has to be the same as the currency of the selected company', ['currency_id', 'company_id']), ] def copy(self, cr, uid, id, default=None, context=None): From 0cb81b94189f012be8dbe3445fa54dcf70407769 Mon Sep 17 00:00:00 2001 From: "ARA (OpenERP)" Date: Fri, 11 Mar 2011 18:33:40 +0530 Subject: [PATCH 3/4] [IMP] Account: changing company currency breaks analytic account bzr revid: ara@tinyerp.com-20110311130340-ur7dilhk4mmsrk5a --- addons/analytic/analytic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index b76071eed7b..77ec4c153c0 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -121,7 +121,7 @@ class account_analytic_account(osv.osv): return result - def _get_company_currency(self, cr, uid, ids, context=None): + def _get_analytic_account(self, cr, uid, ids, context=None): company_obj = self.pool.get('res.company') analytic_obj = self.pool.get('account.analytic.account') accounts = [] @@ -140,7 +140,7 @@ class account_analytic_account(osv.osv): cr.execute("""update account_analytic_account set currency_id=%s where id=%s""", (value, account.id, )) else: - raise osv.except_osv(_('Error !'), _('The currency has to be the same as the currency of the selected company.')) + raise osv.except_osv(_('Error !'), _("The currency has to be the same as the currency of the analytic account's company or empty.")) return True def _currency(self, cr, uid, ids, field_name, arg, context=None): @@ -182,7 +182,7 @@ class account_analytic_account(osv.osv): \n If it is to be reviewed then the state is \'Pending\'.\n When the project is completed the state is set to \'Done\'.'), 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, method=True, store = { - 'res.company': (_get_company_currency, ['currency_id'], 10), + 'res.company': (_get_analytic_account, ['currency_id'], 10), }, string='Currency', type='many2one', relation='res.currency'), } From cee122bcfbc2f5c42cfad57304f92c35c401105d Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 24 Mar 2011 12:12:12 +0100 Subject: [PATCH 4/4] [FIX] analytic: fixed the constraint on currencies on analytic accounts in order to be compliant with analytic accounts that doesn't belong to a company and for which we should be able to set any currency (no constraint in that case, otherwise it has to be the same as company) bzr revid: qdp-launchpad@openerp.com-20110324111212-bal82qcrdhc0pyzh --- addons/analytic/analytic.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index 77ec4c153c0..ee458ca0076 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -133,23 +133,18 @@ class account_analytic_account(osv.osv): if type(ids) != type([]): ids=[ids] for account in self.browse(cr, uid, ids, context=context): - if not value: - cr.execute("""update account_analytic_account set - currency_id=NULL where id=%s""", (account.id, )) - elif account.company_id.currency_id.id == value: - cr.execute("""update account_analytic_account set - currency_id=%s where id=%s""", (value, account.id, )) - else: - raise osv.except_osv(_('Error !'), _("The currency has to be the same as the currency of the analytic account's company or empty.")) - return True + if account.company_id: + if account.company_id.currency_id.id != value: + raise osv.except_osv(_('Error !'), _("If you set a company, the currency selected has to be the same as it's currency. \nYou can remove the company belonging, and thus change the currency, only on analytic account of type 'view'. This can be really usefull for consolidation purposes of several companies charts with different currencies, for example.")) + return cr.execute("""update account_analytic_account set currency_id=%s where id=%s""", (value, account.id, )) def _currency(self, cr, uid, ids, field_name, arg, context=None): result = {} for rec in self.browse(cr, uid, ids, context=context): - if not rec.currency_id.id: - result[rec.id] = False - else: + if rec.company_id: result[rec.id] = rec.company_id.currency_id.id + else: + result[rec.id] = rec.currency_id.id return result _columns = {