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 IN ('purchase','general') \
+ AND account_analytic_journal.type IN ('purchase', 'general') \
GROUP BY account_analytic_account.id;""", (parent_ids,))
for account_id, sum in cr.fetchall():
if account_id not in res:
res = {}
for account in self.browse(cr, uid, ids, context=context):
if account.quantity_max != 0:
- res[account.id] = account.quantity_max - account.hours_quantity
+ res[account.id] = account.quantity_max - account.hours_qtt_invoiced
else:
res[account.id] = 0.0
for id in ids:
result.add(line.account_id.id)
return list(result)
+ def _get_total_estimation(self, account):
+ tot_est = 0.0
+ if account.fix_price_invoices:
+ total_est += account.amount_max
+ if account.invoice_on_timesheets:
+ tot_est += account.hours_qtt_est
+ return tot_est
+
+ def _get_total_invoiced(self, account):
+ total_invoiced = 0.0
+ if account.fix_price_invoices:
+ total_invoiced += account.ca_invoiced
+ if account.invoice_on_timesheets:
+ total_invoiced += account.hours_qtt_invoiced
+ return total_invoiced
+
+ def _get_total_remaining(self, account):
+ total_remaining = 0.0
+ if account.fix_price_invoices:
+ total_remaining += account.remaining_ca
+ if account.invoice_on_timesheets:
+ total_remaining += account.remaining_hours
+ return total_remaining
+
+ def _get_total_toinvoice(self, account):
+ total_toinvoice = 0.0
+ if account.fix_price_invoices:
+ total_toinvoice += account.ca_to_invoice
+ if account.invoice_on_timesheets:
+ total_toinvoice += account.hours_qtt_non_invoiced
+ return total_toinvoice
+
+ def _sum_of_fields(self, cr, uid, ids, name, arg, context=None):
+ res = dict([(i, {}) for i in ids])
+ for account in self.browse(cr, uid, ids, context=context):
+ res[account.id]['est_total'] = self._get_total_estimation(account)
+ res[account.id]['invoiced_total'] = self._get_total_invoiced(account)
+ res[account.id]['remaining_total'] = self._get_total_remaining(account)
+ res[account.id]['toinvoice_total'] = self._get_total_toinvoice(account)
+ return res
+
_columns = {
'is_overdue_quantity' : fields.function(_is_overdue_quantity, method=True, type='boolean', string='Overdue Quantity',
store={
'real_margin_rate': fields.function(_real_margin_rate_calc, type='float', string='Real Margin Rate (%)',
help="Computes using the formula: (Real Margin / Total Costs) * 100.",
digits_compute=dp.get_precision('Account')),
- 'so_visible' : fields.boolean('sale order line visible'),
- 'timsheet_visible' : fields.boolean("On timesheet"),
- 'expense_visible' : fields.boolean('expense line visible'),
+ 'fix_price_invoices' : fields.boolean('Fix Price Invoices'),
+ 'invoice_on_timesheets' : fields.boolean("Invoice On Timesheets"),
'month_ids': fields.function(_analysis_all, multi='analytic_analysis', type='many2many', relation='account_analytic_analysis.summary.month', string='Month'),
'user_ids': fields.function(_analysis_all, multi='analytic_analysis', type="many2many", relation='account_analytic_analysis.summary.user', string='User'),
- 'template_id':fields.many2one('account.analytic.account', 'Template Of Contract'),
- 'fix_exp_max' : fields.float('Max. amt'),
- 'timesheet_max': fields.float('max_timesheet'),
- 'expense_max': fields.float('expenses'),
+ 'template_id':fields.many2one('account.analytic.account', 'Template of Contract'),
+ 'hours_qtt_est': fields.float('Estimation of Hours to Invoice'),
+ '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):
+
+ def on_change_template(self, cr, uid, id, template_id, context=None):
if not template_id:
return {}
res = {'value':{}}
- template = self.browse(cr, uid, template_id)
+ template = self.browse(cr, uid, template_id, context=context)
if template.date_start:
res['value']['date_start'] = str(template.date_start)
if template.date:
res['value']['date'] = str(template.date)
+ res['value']['fix_price_invoices'] = template.fix_price_invoices
+ res['value']['invoice_on_timesheets'] = template.invoice_on_timesheets
res['value']['quantity_max'] = template.quantity_max
res['value']['remaining_hours'] = template.remaining_hours
+ res['value']['amount_max'] = template.amount_max
res['value']['to_invoice'] = template.to_invoice.id
res['value']['pricelist_id'] = template.pricelist_id.id
res['value']['description'] = template.description