[FIX] hr_timesheet_invoice: when reinvoicing costs, force the product should set the product on analytic lines without any + code refactoring and better warning message
lp bug: https://launchpad.net/bugs/976223 fixed bzr revid: qdp-launchpad@openerp.com-20120726113530-rx713dc6sxy1cu2b
This commit is contained in:
parent
f699262170
commit
6c1bc3975e
|
@ -90,32 +90,28 @@ class account_analytic_line(osv.osv):
|
|||
|
||||
context2 = context.copy()
|
||||
context2['lang'] = partner.lang
|
||||
cr.execute("SELECT product_id, to_invoice, sum(unit_amount), product_uom_id " \
|
||||
cr.execute("SELECT product_id, to_invoice, sum(unit_amount), product_uom_id, name " \
|
||||
"FROM account_analytic_line as line " \
|
||||
"WHERE account_id = %s " \
|
||||
"AND id IN %s AND to_invoice IS NOT NULL " \
|
||||
"GROUP BY product_id,to_invoice,product_uom_id", (account.id, tuple(ids),))
|
||||
|
||||
for product_id, factor_id, qty, uom in cr.fetchall():
|
||||
product = product_obj.browse(cr, uid, product_id, context2)
|
||||
for product_id, factor_id, qty, uom, line_name in cr.fetchall():
|
||||
if data.get('product'):
|
||||
product_id = data['product'][0]
|
||||
product = product_obj.browse(cr, uid, product_id, context=context2)
|
||||
if not product:
|
||||
raise osv.except_osv(_('Error'), _('At least one line has no product !'))
|
||||
factor_name = ''
|
||||
factor = invoice_factor_obj.browse(cr, uid, factor_id, context2)
|
||||
if not data.get('product', False):
|
||||
if factor.customer_name:
|
||||
factor_name = product.name+' - '+factor.customer_name
|
||||
else:
|
||||
factor_name = product.name
|
||||
else:
|
||||
data['product'] = data['product'][0]
|
||||
factor_name = product_obj.name_get(cr, uid, [data['product']], context=context)[0][1]
|
||||
raise osv.except_osv(_('Error'), _('There is no product defined for the line %s. Please select one or force the product through the wizard.') % (line_name))
|
||||
factor = invoice_factor_obj.browse(cr, uid, factor_id, context=context2)
|
||||
factor_name = product_obj.name_get(cr, uid, product_id, context=context2)[1]
|
||||
if factor.customer_name:
|
||||
factor_name += ' - ' + factor.customer_name
|
||||
|
||||
ctx = context.copy()
|
||||
ctx.update({'uom':uom})
|
||||
if account.pricelist_id:
|
||||
pl = account.pricelist_id.id
|
||||
price = pro_price_obj.price_get(cr,uid,[pl], data.get('product', False) or product_id, qty or 1.0, account.partner_id.id, context=ctx)[pl]
|
||||
price = pro_price_obj.price_get(cr,uid,[pl], product_id, qty or 1.0, account.partner_id.id, context=ctx)[pl]
|
||||
else:
|
||||
price = 0.0
|
||||
|
||||
|
@ -131,7 +127,7 @@ class account_analytic_line(osv.osv):
|
|||
'invoice_line_tax_id': [(6,0,tax )],
|
||||
'invoice_id': last_invoice,
|
||||
'name': factor_name,
|
||||
'product_id': data.get('product',product_id),
|
||||
'product_id': product_id,
|
||||
'invoice_line_tax_id': [(6,0,tax)],
|
||||
'uos_id': uom,
|
||||
'account_id': account_id,
|
||||
|
@ -179,7 +175,7 @@ class hr_timesheet_invoice_create(osv.osv_memory):
|
|||
'time': fields.boolean('Time spent', help='The time of each work done will be displayed on the invoice'),
|
||||
'name': fields.boolean('Description', help='The detail of each work done will be displayed on the invoice'),
|
||||
'price': fields.boolean('Cost', help='The cost of each work done will be displayed on the invoice. You probably don\'t want to check this'),
|
||||
'product': fields.many2one('product.product', 'Product', help='Fill this field only if you want to force to use a specific product. Keep empty to use the real product that comes from the cost.'),
|
||||
'product': fields.many2one('product.product', 'Force Product', help='Fill this field only if you want to force to use a specific product. Keep empty to use the real product that comes from the cost.'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
|
Loading…
Reference in New Issue