[FIX] analytic_contract_hr_expense: fixed amounts in billing table + view inheritancy
bzr revid: qdp-launchpad@openerp.com-20120618145720-s1bcig0x52vj1t2w
This commit is contained in:
parent
7d7ba1515b
commit
0182e3b17b
|
@ -98,7 +98,7 @@ class account_analytic_account(osv.osv):
|
||||||
WHERE account_analytic_account.id IN %s \
|
WHERE account_analytic_account.id IN %s \
|
||||||
AND account_analytic_line.invoice_id IS NULL \
|
AND account_analytic_line.invoice_id IS NULL \
|
||||||
AND account_analytic_line.to_invoice IS NOT NULL \
|
AND account_analytic_line.to_invoice IS NOT NULL \
|
||||||
AND account_analytic_journal.type IN ('purchase', 'general') \
|
AND account_analytic_journal.type = 'general' \
|
||||||
GROUP BY account_analytic_account.id;""", (parent_ids,))
|
GROUP BY account_analytic_account.id;""", (parent_ids,))
|
||||||
for account_id, sum in cr.fetchall():
|
for account_id, sum in cr.fetchall():
|
||||||
if account_id not in res:
|
if account_id not in res:
|
||||||
|
@ -316,7 +316,7 @@ class account_analytic_account(osv.osv):
|
||||||
res = {}
|
res = {}
|
||||||
for account in self.browse(cr, uid, ids, context=context):
|
for account in self.browse(cr, uid, ids, context=context):
|
||||||
res[account.id] = 0.0
|
res[account.id] = 0.0
|
||||||
line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False)], context=context)
|
line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False), ('journal_id.type', '=', 'general')], context=context)
|
||||||
for line in lines_obj.browse(cr, uid, line_ids, context=context):
|
for line in lines_obj.browse(cr, uid, line_ids, context=context):
|
||||||
res[account.id] += line.invoice_id.amount_untaxed
|
res[account.id] += line.invoice_id.amount_untaxed
|
||||||
return res
|
return res
|
||||||
|
@ -324,10 +324,7 @@ class account_analytic_account(osv.osv):
|
||||||
def _remaining_ca_calc(self, cr, uid, ids, name, arg, context=None):
|
def _remaining_ca_calc(self, cr, uid, ids, name, arg, context=None):
|
||||||
res = {}
|
res = {}
|
||||||
for account in self.browse(cr, uid, ids, context=context):
|
for account in self.browse(cr, uid, ids, context=context):
|
||||||
if account.amount_max != 0:
|
|
||||||
res[account.id] = max(account.amount_max - account.ca_invoiced, account.fix_price_to_invoice)
|
res[account.id] = max(account.amount_max - account.ca_invoiced, account.fix_price_to_invoice)
|
||||||
else:
|
|
||||||
res[account.id]=0.0
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _real_margin_calc(self, cr, uid, ids, name, arg, context=None):
|
def _real_margin_calc(self, cr, uid, ids, name, arg, context=None):
|
||||||
|
|
|
@ -73,39 +73,42 @@ class account_analytic_account(osv.osv):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
if child_ids:
|
if child_ids:
|
||||||
cr.execute("SELECT hel.analytic_account, SUM(hel.unit_amount*hel.unit_quantity) \
|
cr.execute("""SELECT account_analytic_account.id, \
|
||||||
FROM hr_expense_line AS hel\
|
COALESCE(SUM (product_template.list_price * \
|
||||||
LEFT JOIN hr_expense_expense AS he \
|
account_analytic_line.unit_amount * \
|
||||||
ON he.id = hel.expense_id\
|
((100-hr_timesheet_invoice_factor.factor)/100)), 0.0) \
|
||||||
WHERE he.state = 'invoiced' \
|
AS ca_to_invoice \
|
||||||
AND hel.analytic_account IN %s \
|
FROM product_template \
|
||||||
GROUP BY hel.analytic_account",(child_ids,))
|
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 = 'purchase' \
|
||||||
|
GROUP BY account_analytic_account.id;""",(child_ids,))
|
||||||
for account_id, sum in cr.fetchall():
|
for account_id, sum in cr.fetchall():
|
||||||
res[account_id] = sum
|
res[account_id] = sum
|
||||||
res_final = res
|
res_final = res
|
||||||
return res_final
|
return res_final
|
||||||
|
|
||||||
def _expense_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
|
def _expense_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
|
||||||
|
lines_obj = self.pool.get('account.analytic.line')
|
||||||
res = {}
|
res = {}
|
||||||
res_final = {}
|
for account in self.browse(cr, uid, ids, context=context):
|
||||||
child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
|
res[account.id] = 0.0
|
||||||
for i in child_ids:
|
line_ids = lines_obj.search(cr, uid, [('account_id','=', account.id), ('invoice_id','!=',False), ('to_invoice','!=', False), ('journal_id.type', '=', 'purchase')], context=context)
|
||||||
res[i] = 0.0
|
for line in lines_obj.browse(cr, uid, line_ids, context=context):
|
||||||
if not child_ids:
|
res[account.id] += line.invoice_id.amount_untaxed
|
||||||
return res
|
return res
|
||||||
|
|
||||||
if child_ids:
|
|
||||||
cr.execute("SELECT hel.analytic_account,SUM(hel.unit_amount*hel.unit_quantity)\
|
|
||||||
FROM hr_expense_line AS hel\
|
|
||||||
LEFT JOIN hr_expense_expense AS he \
|
|
||||||
ON he.id = hel.expense_id\
|
|
||||||
WHERE he.state = 'paid' \
|
|
||||||
AND hel.analytic_account IN %s \
|
|
||||||
GROUP BY hel.analytic_account",(child_ids,))
|
|
||||||
for account_id, sum in cr.fetchall():
|
|
||||||
res[account_id] = sum
|
|
||||||
res_final = res
|
|
||||||
return res_final
|
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'charge_expenses' : fields.boolean('Charge Expenses'),
|
'charge_expenses' : fields.boolean('Charge Expenses'),
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
<field name="name">account.analytic.account.form.expense.inherit</field>
|
<field name="name">account.analytic.account.form.expense.inherit</field>
|
||||||
<field name="model">account.analytic.account</field>
|
<field name="model">account.analytic.account</field>
|
||||||
<field name="type">form</field>
|
<field name="type">form</field>
|
||||||
<field name="inherit_id" ref="account_analytic_analysis.account_analytic_account_form_form"/>
|
<field eval="60" name="priority"/>
|
||||||
<field eval="20" name="priority"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<xpath expr='//tr[@name="total"]' position='before'>
|
<xpath expr='//tr[@name="total"]' position='before'>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
@ -23,8 +21,8 @@
|
||||||
</td><td>
|
</td><td>
|
||||||
<field class="oe_form_inline" name="expense_to_invoice" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
<field class="oe_form_inline" name="expense_to_invoice" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
||||||
</td><td>
|
</td><td>
|
||||||
<button name="open_hr_expense" string="Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
<button name="open_hr_expense" string="All Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
||||||
<button name="hr_to_invoiced_expense" string="Invoice Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
<button name="hr_to_invoiced_expense" string="Expenses to Invoice" type="object" attrs="{'invisible': [('charge_expenses','=',False)]}"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
Loading…
Reference in New Issue