[IMP]create function for open hr_expense for current analytic_id in hr_expense line and improve code
bzr revid: sgo@tinyerp.com-20120531072758-fhaake1kjj13iiwi
This commit is contained in:
@@ -381,6 +381,34 @@ class account_analytic_account(osv.osv):
|
||||
for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context):
|
||||
result.add(line.account_id.id)
|
||||
return list(result)
|
||||
|
||||
def _sum_of_fields(self, cr, uid, ids, name, arg, context=None):
|
||||
res = dict([(i, {}) for i in ids])
|
||||
total_max = 0.0
|
||||
total_invoiced = 0.0
|
||||
total_toinvoice = 0.0
|
||||
total_remaining = 0.0
|
||||
for account in self.browse(cr, uid, ids, context=context):
|
||||
if account.fix_price_invoices:
|
||||
total_max += account.amount_max
|
||||
total_invoiced += account.ca_invoiced
|
||||
total_remaining += account.remaining_ca
|
||||
total_toinvoice += account.ca_to_invoice
|
||||
if account.invoice_on_timesheets:
|
||||
total_max += account.quantity_max
|
||||
total_invoiced += account.hours_qtt_invoiced
|
||||
total_remaining += account.remaining_hours
|
||||
total_toinvoice += account.hours_qtt_non_invoiced
|
||||
if account.charge_expenses:
|
||||
total_max += account.expense_max
|
||||
total_invoiced += account.expense_invoiced
|
||||
total_remaining += account.remaining_expense
|
||||
total_toinvoice += account.expense_to_invoice
|
||||
res[account.id]['est_total'] = total_max or 0.0
|
||||
res[account.id]['invoiced_total'] = total_invoiced or 0.0
|
||||
res[account.id]['remaining_total'] = total_remaining or 0.0
|
||||
res[account.id]['toinvoice_total'] = total_toinvoice or 0.0
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'is_overdue_quantity' : fields.function(_is_overdue_quantity, method=True, type='boolean', string='Overdue Quantity',
|
||||
@@ -440,6 +468,10 @@ class account_analytic_account(osv.osv):
|
||||
#'fix_exp_max' : fields.float('Max. amt'),
|
||||
#'timesheet_max': fields.float('max_timesheet'),
|
||||
'expense_max': fields.float('expenses'),
|
||||
'est_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
|
||||
'invoiced_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
|
||||
'remaining_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
|
||||
'toinvoice_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
|
||||
}
|
||||
def on_change_template(self, cr, uid, id, template_id):
|
||||
if not template_id:
|
||||
@@ -456,6 +488,39 @@ class account_analytic_account(osv.osv):
|
||||
res['value']['pricelist_id'] = template.pricelist_id.id
|
||||
res['value']['description'] = template.description
|
||||
return res
|
||||
|
||||
def open_hr_expense(self, cr, uid, ids, context=None):
|
||||
account = self.browse(cr, uid, ids[0], context)
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
try:
|
||||
journal_id = data_obj.get_object(cr, uid, 'hr_timesheet', 'analytic_journal').id
|
||||
except ValueError:
|
||||
journal_id = False
|
||||
line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
|
||||
id2 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_form')
|
||||
id3 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_tree')
|
||||
if id2:
|
||||
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
||||
if id3:
|
||||
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
|
||||
domain = [('line_ids','in',line_ids)]
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Expenses'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'views': [(id3,'tree'),(id2,'form')],
|
||||
'domain' : domain,
|
||||
'res_model': 'hr.expense.expense',
|
||||
'nodestroy': True,
|
||||
}
|
||||
|
||||
def hr_to_invoiced_expense(self, cr, uid, ids, context=None):
|
||||
res = self.open_hr_expense(cr,uid,ids,context)
|
||||
account = self.browse(cr, uid, ids[0], context)
|
||||
line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
|
||||
res['domain'] = [('line_ids','in',line_ids),('state','=','invoiced')]
|
||||
return res
|
||||
|
||||
account_analytic_account()
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
res_model="account.analytic.line"
|
||||
src_model="account.analytic.account"
|
||||
/>
|
||||
|
||||
|
||||
<record id="hr_timesheet.account_analytic_account_form_form" model="ir.ui.view">
|
||||
<field name="name">account.analytic.account.invoice.form.inherit</field>
|
||||
<field name="model">account.analytic.account</field>
|
||||
@@ -101,16 +101,16 @@
|
||||
<td class="oe_amount_center oe_th_110px oe_border_right"><field name="remaining_expense" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
|
||||
<td class="oe_amount_center oe_th_110px"><field name="expense_to_invoice" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
|
||||
<td width="10px"></td>
|
||||
<td class="oe_th_150px">todo</td>
|
||||
<td class="oe_th_150px">todo</td>
|
||||
<td class="oe_th_150px"><button class= "oe_btn_width" name="open_hr_expense" string="Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
|
||||
<td class="oe_th_150px"><button class= "oe_btn_width" name="hr_to_invoiced_expense" string="Invoice Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="oe_border_right">Total</th>
|
||||
<td width="10px"></td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top">todo</td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top">todo</td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_right oe_border_top">todo</td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top">todo</td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top"><field name="est_total" nolabel="1"/></td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top"><field name="invoiced_total" nolabel="1"/></td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_right oe_border_top"><field name="remaining_total" nolabel="1"/></td>
|
||||
<td class="oe_amount_center oe_th_110px oe_border_top"><field name="toinvoice_total" nolabel="1"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user