[MERGE] Account: Account analytic line => Onchange amount improved & code refactor
bzr revid: mra@mra-laptop-20101028094609-418e9h98a3bmdehn
This commit is contained in:
parent
e04b0e3e8a
commit
8328597b0f
|
@ -41,7 +41,7 @@ class account_analytic_line(osv.osv):
|
|||
}
|
||||
|
||||
_defaults = {
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': 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),
|
||||
}
|
||||
_order = 'date desc'
|
||||
|
@ -64,8 +64,6 @@ class account_analytic_line(osv.osv):
|
|||
if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id:
|
||||
return False
|
||||
return True
|
||||
_constraints = [
|
||||
]
|
||||
|
||||
# Compute the cost based on the price type define into company
|
||||
# property_valuation_price_type property
|
||||
|
@ -80,12 +78,12 @@ class account_analytic_line(osv.osv):
|
|||
return {}
|
||||
product_obj = self.pool.get('product.product')
|
||||
analytic_journal_obj =self.pool.get('account.analytic.journal')
|
||||
company_obj = self.pool.get('res.company')
|
||||
# company_obj = self.pool.get('res.company')
|
||||
product_price_type_obj = self.pool.get('product.price.type')
|
||||
j_id = analytic_journal_obj.browse(cr, uid, journal_id, context=context)
|
||||
prod = product_obj.browse(cr, uid, prod_id)
|
||||
if not company_id:
|
||||
company_id = j_id.company_id.id
|
||||
# if not company_id:
|
||||
# company_id = j_id.company_id.id
|
||||
result = 0.0
|
||||
|
||||
if j_id.type <> 'sale':
|
||||
|
@ -97,7 +95,7 @@ class account_analytic_line(osv.osv):
|
|||
_('There is no expense account defined ' \
|
||||
'for this product: "%s" (id:%d)') % \
|
||||
(prod.name, prod.id,))
|
||||
amount_unit = prod.price_get('standard_price', context)[prod.id]
|
||||
# amount_unit = prod.price_get('standard_price', context)[prod.id]
|
||||
else:
|
||||
a = prod.product_tmpl_id.property_account_income.id
|
||||
if not a:
|
||||
|
@ -107,10 +105,12 @@ class account_analytic_line(osv.osv):
|
|||
_('There is no income account defined ' \
|
||||
'for this product: "%s" (id:%d)') % \
|
||||
(prod.name, prod_id,))
|
||||
amount_unit = prod.price_get('list_price', context)[prod_id]
|
||||
# amount_unit = prod.price_get('list_price', context)[prod_id]
|
||||
|
||||
if not company_id:
|
||||
company_id = company_obj._company_default_get(cr, uid, 'account.analytic.line', context=context)
|
||||
# if not company_id:
|
||||
# company_id = company_obj._company_default_get(cr, uid, 'account.analytic.line', context=context)
|
||||
# # so what? do we need company_id?
|
||||
if True:
|
||||
flag = False
|
||||
# Compute based on pricetype
|
||||
product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','standard_price')], context)
|
||||
|
@ -124,12 +124,18 @@ class account_analytic_line(osv.osv):
|
|||
# Take the company currency as the reference one
|
||||
if pricetype.field == 'list_price':
|
||||
flag = True
|
||||
amount_unit = prod.price_get(pricetype.field, context)[prod.id]
|
||||
ctx = context.copy()
|
||||
if unit:
|
||||
# price_get() will respect a 'uom' in its context, in order
|
||||
# to return a default price for those units
|
||||
ctx['uom'] = unit
|
||||
amount_unit = prod.price_get(pricetype.field, context=ctx)[prod.id]
|
||||
prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
|
||||
amount = amount_unit*unit or 1.0
|
||||
amount = amount_unit * quantity or 1.0
|
||||
result = round(amount, prec)
|
||||
if not flag:
|
||||
result *= -1
|
||||
|
||||
return {'value': {
|
||||
'amount': result,
|
||||
'general_account_id': a,
|
||||
|
@ -153,11 +159,10 @@ class res_partner(osv.osv):
|
|||
_inherit = 'res.partner'
|
||||
|
||||
_columns = {
|
||||
'contract_ids': fields.one2many('account.analytic.account', \
|
||||
'contract_ids': fields.one2many('account.analytic.account', \
|
||||
'partner_id', 'Contracts', readonly=True),
|
||||
}
|
||||
}
|
||||
|
||||
res_partner()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue