[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
This commit is contained in:
qdp-launchpad@tinyerp.com 2010-09-06 12:33:34 +02:00
parent a5df6a53bd
commit 2b0a9f5de3
3 changed files with 11 additions and 64 deletions

View File

@ -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),

View File

@ -25,8 +25,8 @@
<field name="arch" type="xml">
<search string="Analytic Account">
<group col="8" colspan="4">
<filter icon="terp-check" string="Current" domain="[('state','=','open')]" help="Current Accounts"/>
<filter icon="terp-gtk-media-pause" string="Pending" domain="[('state','=','pending')]" help="Pending Accounts"/>
<filter icon="terp-camera_test" string="Current" domain="[('state','=','open')]" help="Current Accounts"/>
<separator orientation="vertical"/>
<field name="name" select="1"/>
<field name="code" select="1"/>
@ -38,7 +38,7 @@
<filter string="Parent" icon="terp-folder-orange" domain="[]" context="{'group_by':'parent_id'}"/>
<filter string="Type" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'type'}"/>
<separator orientation="vertical"/>
<filter string="Associated Partner" icon="terp-personal" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="Associated Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="Manager" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
</group>
</search>
@ -59,7 +59,7 @@
<field name="debit"/>
<field name="credit"/>
<field name="balance"/>
<field name="company_currency_id"/>
<field name="currency_id"/>
<field name="date" invisible="1"/>
</tree>
</field>
@ -77,7 +77,7 @@
<field name="parent_id" on_change="on_change_parent(parent_id)" groups="base.group_extended"/>
<field name="company_id" select="2" widget="selection" groups="base.group_multi_company"/>
<field name="type" select="2"/>
<field name="company_currency_id" select="2"/>
<field name="currency_id" select="2"/>
</group>
<notebook colspan="4">
<page string="Account Data">
@ -105,7 +105,6 @@
<field name="view_type">form</field>
<field name="view_mode">tree,graph,form</field>
<field name="view_id" ref="view_account_analytic_account_tree"/>
<field name="context">{"search_default_user_id":uid}</field>
<field name="search_view_id" ref="account.view_account_analytic_account_search"/>
</record>
<menuitem action="action_account_analytic_account_form" id="account_analytic_def_account" parent="menu_analytic_accounting" groups="base.group_extended"/>

View File

@ -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 = {