#
##############################################################################
-import time
-
from osv import fields
from osv import osv
from tools.translate import _
'product_uom_id': fields.many2one('product.uom', 'UoM'),
'product_id': fields.many2one('product.product', 'Product'),
'general_account_id': fields.many2one('account.account', 'General Account', required=True, ondelete='restrict'),
- 'move_id': fields.many2one('account.move.line', 'Move Line', ondelete='restrict', select=True),
+ 'move_id': fields.many2one('account.move.line', 'Move Line', ondelete='cascade', select=True),
'journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='restrict', select=True),
'code': fields.char('Code', size=8),
'ref': fields.char('Ref.', size=64),
}
_defaults = {
- 'date': lambda *a: time.strftime('%Y-%m-%d'),
+ 'date': fields.date.context_today,
'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'
if context is None:
context = {}
if context.get('from_date',False):
- args.append(['date', '>=',context['from_date']])
-
+ args.append(['date', '>=', context['from_date']])
if context.get('to_date',False):
- args.append(['date','<=',context['to_date']])
-
+ args.append(['date','<=', context['to_date']])
return super(account_analytic_line, self).search(cr, uid, args, offset, limit,
order, context=context, count=count)
j_id = analytic_journal_obj.browse(cr, uid, journal_id, context=context)
prod = product_obj.browse(cr, uid, prod_id, context=context)
result = 0.0
-
+ if prod_id:
+ unit = prod.uom_id.id
+ if j_id.type == 'purchase':
+ unit = prod.uom_po_id.id
if j_id.type <> 'sale':
a = prod.product_tmpl_id.property_account_expense.id
if not a:
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 * quantity or 1.0
+ amount = amount_unit * quantity or 0.0
result = round(amount, prec)
if not flag:
result *= -1
-
return {'value': {
'amount': result,
'general_account_id': a,
+ 'product_uom_id': unit
}
}