From 2b0a9f5de3f330ec645d21d71b2dfe6532288618 Mon Sep 17 00:00:00 2001
From: "qdp-launchpad@tinyerp.com" <>
Date: Mon, 6 Sep 2010 12:33:34 +0200
Subject: [PATCH] [IMP] analytic & account: move the amount_currency and
currency_id fields on analytic line from module analytic to account, and
replaced with a fields.related [IMP] analytic & account: usability small
changes [IMP] analytic: removed company_currency_id field on analytic account
(duplicated field) [IMP] analytic: put related fields when necessary
bzr revid: qdp-launchpad@tinyerp.com-20100906103334-nhyp1wcghs60c7qj
---
addons/account/account_analytic_line.py | 3 ++
addons/account/project/project_view.xml | 9 ++--
addons/analytic/analytic.py | 63 ++-----------------------
3 files changed, 11 insertions(+), 64 deletions(-)
diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py
index 36fc350dfb8..e162d75fffe 100644
--- a/addons/account/account_analytic_line.py
+++ b/addons/account/account_analytic_line.py
@@ -38,7 +38,10 @@ class account_analytic_line(osv.osv):
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True),
'code' : fields.char('Code', size=8),
'ref': fields.char('Ref.', size=64),
+ 'currency_id': fields.related('move_id', 'currency_id', type='many2one', relation='res.currency', string='Account currency', store=True, help="The related account currency if not equal to the company one."),
+ 'amount_currency': fields.related('move_id', 'amount_currency', type='float', string='Amount currency', store=True, help="The amount expressed in the related account currency if not equal to the company one."),
}
+
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml
index 932fa0495a3..2fdba6559d8 100644
--- a/addons/account/project/project_view.xml
+++ b/addons/account/project/project_view.xml
@@ -25,8 +25,8 @@
-
+
@@ -38,7 +38,7 @@
-
+
@@ -59,7 +59,7 @@
-
+
@@ -77,7 +77,7 @@
-
+
@@ -105,7 +105,6 @@
form
tree,graph,form
- {"search_default_user_id":uid}
diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py
index 6393a471b21..637f90d3e44 100644
--- a/addons/analytic/analytic.py
+++ b/addons/analytic/analytic.py
@@ -173,16 +173,6 @@ class account_analytic_account(osv.osv):
res = self.name_get(cr, uid, ids)
return dict(res)
- def _get_company_currency(self, cr, uid, ids, field_name, arg, context=None):
- result = {}
- for rec in self.browse(cr, uid, ids, context):
- result[rec.id] = (rec.company_id.currency_id.id,rec.company_id.currency_id.code) or False
- return result
-
- def _get_account_currency(self, cr, uid, ids, field_name, arg, context=None):
- result=self._get_company_currency(cr, uid, ids, field_name, arg, context={})
- return result
-
_columns = {
'name' : fields.char('Account Name', size=128, required=True),
'complete_name': fields.function(_complete_name_calc, method=True, type='char', string='Full Account Name'),
@@ -203,7 +193,6 @@ class account_analytic_account(osv.osv):
'date_start': fields.date('Date Start'),
'date': fields.date('Date End'),
'company_id': fields.many2one('res.company', 'Company', required=True),
- 'company_currency_id': fields.function(_get_company_currency, method=True, type='many2one', relation='res.currency', string='Currency'),
'state': fields.selection([('draft','Draft'),('open','Open'), ('pending','Pending'),('cancelled', 'Cancelled'),('close','Closed'),('template', 'Template')], 'State', required=True,
help='* When an account is created its in \'Draft\' state.\
\n* If any associated partner is there, it can be in \'Open\' state.\
@@ -211,7 +200,7 @@ 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.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', store=True),
+ 'currency_id': fields.related('company_id', 'currency_id', type='many2one', relation='res.currency', string='Account currency', store=True, readonly=True),
}
def _default_company(self, cr, uid, context=None):
@@ -280,59 +269,15 @@ account_analytic_account()
class account_analytic_line(osv.osv):
_name = 'account.analytic.line'
_description = 'Analytic Line'
- def _amount_currency(self, cr, uid, ids, field_name, arg, context=None):
- result = {}
- for rec in self.browse(cr, uid, ids, context=context):
- cmp_cur_id=rec.company_id.currency_id.id
- aa_cur_id=rec.account_id.currency_id.id
- # Always provide the amount in currency
- if cmp_cur_id != aa_cur_id:
- cur_obj = self.pool.get('res.currency')
- ctx = {}
- if rec.date and rec.amount:
- ctx['date'] = rec.date
- result[rec.id] = cur_obj.compute(cr, uid, rec.company_id.currency_id.id,
- rec.account_id.currency_id.id, rec.amount,
- context=ctx)
- else:
- result[rec.id]=rec.amount
- return result
-
- def _get_account_currency(self, cr, uid, ids, field_name, arg, context=None):
- result = {}
- for rec in self.browse(cr, uid, ids, context):
- # Always provide second currency
- result[rec.id] = (rec.account_id.currency_id.id,rec.account_id.currency_id.code)
- return result
- def _get_account_line(self, cr, uid, ids, context=None):
- aac_ids = {}
- for acc in self.pool.get('account.analytic.account').browse(cr, uid, ids):
- aac_ids[acc.id] = True
- aal_ids = []
- if aac_ids:
- aal_ids = self.pool.get('account.analytic.line').search(cr, uid, [('account_id','in',aac_ids.keys())], context=context)
- return aal_ids
_columns = {
'name' : fields.char('Description', size=256, required=True),
'date' : fields.date('Date', required=True, select=1),
- 'amount' : fields.float('Amount', required=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price.'),
+ 'amount' : fields.float('Amount', required=True, help='Calculated by multiplying the quantity and the price given in the Product\'s cost price. Always expressed in the company main currency.'),
'unit_amount' : fields.float('Quantity', help='Specifies the amount of quantity to count.'),
'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
- 'user_id' : fields.many2one('res.users', 'User',),
- 'company_id': fields.many2one('res.company','Company',required=True),
- 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency',
- store={
- 'account.analytic.account': (_get_account_line, ['company_id'], 50),
- 'account.analytic.line': (lambda self, cr, uid, ids, c={}: ids, ['amount','unit_amount'],10),
- },
- help="The related account currency if not equal to the company one."),
- 'amount_currency': fields.function(_amount_currency, method=True, digits_compute= dp.get_precision('Account'), string='Amount currency',
- store={
- 'account.analytic.account': (_get_account_line, ['company_id'], 50),
- 'account.analytic.line': (lambda self, cr, uid, ids, c={}: ids, ['amount','unit_amount'],10),
- },
- help="The amount expressed in the related account currency if not equal to the company one."),
+ 'user_id' : fields.many2one('res.users', 'User'),
+ 'company_id': fields.related('account_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
}
_defaults = {