[IMP] Add trigger on analytic line, so currency and amount currency are recomputed if company change
[REM] Remove the currency_id of analytic account to be computed based on sale pricelist, it's now the reported company currency_id [ADD] some demo to demo data provided by multicompany module bzr revid: joel.grandguillaume@camptocamp.com-20091217164253-3jwugrn14mkj21pe
This commit is contained in:
parent
a7c8200828
commit
97d33b0da5
|
@ -55,7 +55,16 @@ class account_analytic_line(osv.osv):
|
|||
else:
|
||||
result[rec.id] = False
|
||||
return result
|
||||
|
||||
|
||||
def _get_account_line(self, cr, uid, ids, context={}):
|
||||
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),
|
||||
|
@ -70,13 +79,17 @@ class account_analytic_line(osv.osv):
|
|||
'code' : fields.char('Code', size=8),
|
||||
'user_id' : fields.many2one('res.users', 'User',),
|
||||
'ref': fields.char('Ref.', size=32),
|
||||
'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Currency',
|
||||
store=True, help="The related account currency if not equal to the company one."),
|
||||
'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),
|
||||
},
|
||||
help="The related account currency if not equal to the company one."),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
'amount_currency': fields.function(_amount_currency, method=True, digits=(16, int(config['price_accuracy'])), string='Amount currency',
|
||||
store=True,
|
||||
help="The amount expressed in the related account currency if not equal to the company one.",
|
||||
),
|
||||
store={
|
||||
'account.analytic.account': (_get_account_line, ['company_id'], 50),
|
||||
},
|
||||
help="The amount expressed in the related account currency if not equal to the company one.",),
|
||||
|
||||
}
|
||||
_defaults = {
|
||||
|
|
|
@ -183,7 +183,10 @@ class account_analytic_account(osv.osv):
|
|||
and amount_currency<0 \
|
||||
GROUP BY account_analytic_line.account_id"""%acc_set)
|
||||
for account_id, sum in cr.fetchall():
|
||||
res[account_id] += round(sum,2)
|
||||
if res.has_key(account_id):
|
||||
res[account_id] += round(sum,2)
|
||||
else:
|
||||
res[account_id] = round(sum,2)
|
||||
for obj_id in ids:
|
||||
res.setdefault(obj_id, 0.0)
|
||||
for child_id in self.search(cr, uid,
|
||||
|
|
|
@ -52,15 +52,15 @@ class account_analytic_account(osv.osv):
|
|||
res[id] = round(res.get(id, 0.0),2)
|
||||
return res
|
||||
|
||||
def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
result=super(account_analytic_account, self)._get_account_currency(cr, uid, ids, field_name, arg, context)
|
||||
for rec in self.browse(cr, uid, ids, context):
|
||||
result[rec.id] = rec.pricelist_id and (rec.pricelist_id.currency_id.id,rec.pricelist_id.currency_id.code) or result[rec.id]
|
||||
return result
|
||||
# def _get_account_currency(self, cr, uid, ids, field_name, arg, context={}):
|
||||
# result=super(account_analytic_account, self)._get_account_currency(cr, uid, ids, field_name, arg, context)
|
||||
# for rec in self.browse(cr, uid, ids, context):
|
||||
# result[rec.id] = rec.pricelist_id and (rec.pricelist_id.currency_id.id,rec.pricelist_id.currency_id.code) or result[rec.id]
|
||||
# return result
|
||||
|
||||
_inherit = "account.analytic.account"
|
||||
_columns = {
|
||||
'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', store=True),
|
||||
# 'currency_id': fields.function(_get_account_currency, method=True, type='many2one', relation='res.currency', string='Account currency', store=True),
|
||||
'pricelist_id' : fields.many2one('product.pricelist', 'Sale Pricelist'),
|
||||
'amount_max': fields.float('Max. Invoice Price'),
|
||||
'amount_invoiced': fields.function(_invoiced_calc, method=True, string='Invoiced Amount',
|
||||
|
|
|
@ -1,6 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
|
||||
<!-- Valuation pricelist -->
|
||||
<record id="list_usd" model="product.pricelist">
|
||||
<field name="name">Valuation Pricelist USD</field>
|
||||
<field name="type">valuation</field>
|
||||
<field name="currency_id" search="[('code','=','USD')]"/>
|
||||
</record>
|
||||
<record id="ver_usd" model="product.pricelist.version">
|
||||
<field name="pricelist_id" ref="list_usd"/>
|
||||
<field name="name">Default Valuation Pricelist Version USD</field>
|
||||
</record>
|
||||
<record id="item_usd" model="product.pricelist.item">
|
||||
<field name="price_version_id" ref="ver_usd"/>
|
||||
<field name="base" ref="product.standard_price"/>
|
||||
<field name="name">Default Valuation Pricelist Line USD</field>
|
||||
</record>
|
||||
|
||||
<!-- Partner -->
|
||||
<record id="base.main_partner" model="res.partner">
|
||||
<field name="name">OpenERP Corp.</field>
|
||||
|
@ -29,26 +47,32 @@
|
|||
<field name="partner_id" ref="res_partner_oerp_editor"/>
|
||||
<field name="parent_id" ref="base.main_company"/>
|
||||
<field name="name">OpenERP Editor</field>
|
||||
<field name="currency_id" search="[('code','=','EUR')]"/>
|
||||
</record>
|
||||
<record id="res_company_oerp_us" model="res.company">
|
||||
<field name="partner_id" ref="res_partner_oerp_us"/>
|
||||
<field name="parent_id" ref="res_company_oerp_editor"/>
|
||||
<field name="name">OpenERP US</field>
|
||||
<field name="currency_id" search="[('code','=','USD')]"/>
|
||||
<field name="property_valuation_pricelist" ref="list_usd"/>
|
||||
</record>
|
||||
<record id="res_company_oerp_be" model="res.company">
|
||||
<field name="partner_id" ref="res_partner_oerp_be"/>
|
||||
<field name="parent_id" ref="res_company_oerp_editor"/>
|
||||
<field name="name">OpenERP BE</field>
|
||||
<field name="currency_id" search="[('code','=','EUR')]"/>
|
||||
</record>OpenERP IN
|
||||
<record id="res_company_oerp_in" model="res.company">
|
||||
<field name="partner_id" ref="res_partner_oerp_in"/>
|
||||
<field name="parent_id" ref="res_company_oerp_editor"/>
|
||||
<field name="name">OpenERP IN</field>
|
||||
<field name="currency_id" search="[('code','=','EUR')]"/>
|
||||
</record>
|
||||
<record id="res_company_odoo" model="res.company">
|
||||
<field name="partner_id" ref="res_partner_odoo"/>
|
||||
<field name="parent_id" ref="base.main_company"/>
|
||||
<field name="name">Odoo</field>
|
||||
<field name="currency_id" search="[('code','=','EUR')]"/>
|
||||
</record>
|
||||
|
||||
<!-- User -->
|
||||
|
|
Loading…
Reference in New Issue