[IMP] invoice on timesheet using user price
bzr revid: fp@openerp.com-20121028121730-1sbhsoyxa220oktn
This commit is contained in:
parent
af4b056f24
commit
eff45f038d
|
@ -74,36 +74,18 @@ class account_analytic_account(osv.osv):
|
|||
for id in ids:
|
||||
res[id][f] = 0.0
|
||||
res2 = {}
|
||||
if parent_ids:
|
||||
# Amount uninvoiced hours to invoice at sale price
|
||||
# Warning
|
||||
# This computation doesn't take care of pricelist !
|
||||
# Just consider list_price
|
||||
cr.execute("""SELECT account_analytic_account.id, \
|
||||
COALESCE(SUM (product_template.list_price * \
|
||||
account_analytic_line.unit_amount * \
|
||||
((100-hr_timesheet_invoice_factor.factor)/100)), 0.0) \
|
||||
AS ca_to_invoice \
|
||||
FROM product_template \
|
||||
JOIN product_product \
|
||||
ON product_template.id = product_product.product_tmpl_id \
|
||||
JOIN account_analytic_line \
|
||||
ON account_analytic_line.product_id = product_product.id \
|
||||
JOIN account_analytic_journal \
|
||||
ON account_analytic_line.journal_id = account_analytic_journal.id \
|
||||
JOIN account_analytic_account \
|
||||
ON account_analytic_account.id = account_analytic_line.account_id \
|
||||
JOIN hr_timesheet_invoice_factor \
|
||||
ON hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \
|
||||
WHERE account_analytic_account.id IN %s \
|
||||
AND account_analytic_line.invoice_id IS NULL \
|
||||
AND account_analytic_line.to_invoice IS NOT NULL \
|
||||
AND account_analytic_journal.type = 'general' \
|
||||
GROUP BY account_analytic_account.id;""", (parent_ids,))
|
||||
for account_id, sum in cr.fetchall():
|
||||
if account_id not in res:
|
||||
res[account_id] = {}
|
||||
res[account_id][f] = round(sum, dp)
|
||||
for account in accounts:
|
||||
cr.execute("SELECT product_id, user_id, to_invoice, sum(unit_amount), product_uom_id, name " \
|
||||
"FROM account_analytic_line as line " \
|
||||
"WHERE account_id = %s " \
|
||||
"AND invoice_id is NULL AND to_invoice IS NOT NULL " \
|
||||
"GROUP BY product_id, user_id, to_invoice, product_uom_id, name", (account.id,))
|
||||
|
||||
res[account.id][f] = 0.0
|
||||
for product_id, user_id, factor_id, qty, uom, line_name in cr.fetchall():
|
||||
price = self.pool.get('account.analytic.line')._get_invoice_price(cr, uid, account, product_id, user_id, qty, context)
|
||||
factor = self.pool.get('hr_timesheet_invoice.factor').browse(cr, uid, factor_id, context=context)
|
||||
res[account.id][f] += price * qty * (100-factor.factor or 0.0) / 100.0
|
||||
|
||||
# sum both result on account_id
|
||||
for id in ids:
|
||||
|
|
|
@ -146,5 +146,13 @@ class hr_analytic_timesheet(osv.osv):
|
|||
res ['value']['general_account_id']= a
|
||||
return res
|
||||
|
||||
hr_analytic_timesheet()
|
||||
class account_analytic_line(osv.osv):
|
||||
_inherit = "account.analytic.line"
|
||||
def _get_invoice_price(self, cr, uid, account, product_id, user_id, qty, context = {}):
|
||||
print 'Call'
|
||||
for grid in account.user_product_ids:
|
||||
if grid.user_id.id==user_id:
|
||||
print '***', grid.price
|
||||
return grid.price
|
||||
return super(account_analytic_line, self)._get_invoice_price(cr, uid, account, product_id, user_id, qty, context)
|
||||
|
||||
|
|
|
@ -29,6 +29,15 @@ from tools.translate import _
|
|||
|
||||
class account_analytic_line(osv.osv):
|
||||
_inherit = "account.analytic.line"
|
||||
def _get_invoice_price(self, cr, uid, account, product_id, user_id, qty, context = {}):
|
||||
pro_price_obj = self.pool.get('product.pricelist')
|
||||
if account.pricelist_id:
|
||||
pl = account.pricelist_id.id
|
||||
price = pro_price_obj.price_get(cr,uid,[pl], product_id, qty or 1.0, account.partner_id.id, context=context)[pl]
|
||||
else:
|
||||
price = 0.0
|
||||
return price
|
||||
|
||||
|
||||
#
|
||||
# data = {
|
||||
|
@ -45,7 +54,6 @@ class account_analytic_line(osv.osv):
|
|||
invoice_obj = self.pool.get('account.invoice')
|
||||
product_obj = self.pool.get('product.product')
|
||||
invoice_factor_obj = self.pool.get('hr_timesheet_invoice.factor')
|
||||
pro_price_obj = self.pool.get('product.pricelist')
|
||||
fiscal_pos_obj = self.pool.get('account.fiscal.position')
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
|
@ -99,13 +107,13 @@ class account_analytic_line(osv.osv):
|
|||
last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context2)
|
||||
invoices.append(last_invoice)
|
||||
|
||||
cr.execute("SELECT product_id, to_invoice, sum(unit_amount), product_uom_id, name " \
|
||||
cr.execute("SELECT product_id, user_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, name", (account.id, tuple(ids),))
|
||||
"GROUP BY product_id, user_id, to_invoice, product_uom_id, name", (account.id, tuple(ids),))
|
||||
|
||||
for product_id, factor_id, qty, uom, line_name in cr.fetchall():
|
||||
for product_id, user_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)
|
||||
|
@ -118,11 +126,8 @@ class account_analytic_line(osv.osv):
|
|||
|
||||
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], product_id, qty or 1.0, account.partner_id.id, context=ctx)[pl]
|
||||
else:
|
||||
price = 0.0
|
||||
|
||||
price = self._get_invoice_price(cr, uid, account, product_id, user_id, qty, ctx)
|
||||
|
||||
general_account = product.product_tmpl_id.property_account_income or product.categ_id.property_account_income_categ
|
||||
if not general_account:
|
||||
|
|
Loading…
Reference in New Issue