[ADD]on change to compute indicative costs subtotal in contract view

bzr revid: csn@openerp.com-20121029133534-i51j5h1ybpt1ljwd
This commit is contained in:
Cedric Snauwaert 2012-10-29 14:35:34 +01:00
parent 62a7cacdeb
commit 85e2cc3af4
2 changed files with 33 additions and 4 deletions

View File

@ -1086,6 +1086,31 @@ class fleet_vehicle_log_contract(osv.Model):
model_id = False
return model_id
def on_change_indic_cost(self,cr,uid,ids,cost_ids,context=None):
contracts = self.browse(cr,uid,ids,context=context)
totalsum=0
for element in contracts:
for cost in element.cost_ids:
totalsum=totalsum+cost.amount
for element in cost_ids:
if element[1] is False and element[2] is not False:
totalsum = totalsum+element[2]['amount']
return {
'value' : {
'sum_cost' : totalsum,
}
}
def _get_sum_cost(self, cr, uid, ids, odometer_id, arg, context):
contracts = self.browse(cr,uid,ids,context=context)
totalsum=0
res = []
for element in contracts:
for cost in element.cost_ids:
totalsum=totalsum+cost.amount
res.append((element.id,totalsum))
return dict(res)
_name = 'fleet.vehicle.log.contract'
_order='state,expiration_date'
_columns = {
@ -1108,6 +1133,7 @@ class fleet_vehicle_log_contract(osv.Model):
'cost_generated': fields.float('Recurring Cost Amount',help="Costs paid at regular intervals, depending on the cost frequency. If the cost frequency is set to unique, the cost will be logged at the start date"),
'cost_frequency': fields.selection([('no','No'),('daily', 'Daily'),('weekly','Weekly'),('monthly','Monthly'),('yearly','Yearly')], 'Recurring Cost Frequency', help='Frequency of the recuring cost',required=True),
'generated_cost_ids' : fields.one2many('fleet.vehicle.cost', 'contract_id', 'Generated Costs',ondelete='cascade'),
'sum_cost' : fields.function(_get_sum_cost,type='float', string='Indicative Costs Total',readonly=True),
}
_defaults = {
'purchaser_id': lambda self, cr, uid, ctx: uid,

View File

@ -404,21 +404,24 @@
<notebook>
<page string="Included Services">
<group>
<field name="cost_ids" context="{'vehicle_id': vehicle_id}" nolabel="1">
<field name="cost_ids" context="{'vehicle_id': vehicle_id}" nolabel="1" on_change="on_change_indic_cost(cost_ids)">
<tree version="7.0" editable="bottom">
<field name="cost_subtype" string="Service" domain="[('category','=','service')]"/>
<field name="amount" sum="Price" string="Indicative Cost" />
</tree>
</field>
</group>
<div class="oe_right"><group><field name="sum_cost" string="Indicative Costs Total"/></group></div>
</page>
<page string="Generated Costs">
<group>
<field name="generated_cost_ids" context="{'vehicle_id': vehicle_id}" nolabel="1">
<tree version="7.0" editable="bottom">
<field name="generated_cost_ids" context="{'vehicle_id': vehicle_id}" nolabel="1" sum="amount">
<tree version="7.0" editable="bottom" >
<field name="date" />
<field name="amount" />
<field name="amount" sum="amount"/>
</tree>
</field>
</group>
</page>