Reputation: 3
I am having issues with getting a function field to calculate a discount, taxes and total in one list.
i am working with openerp 7. here is my code:
def _total(self,cr,uid,ids,field_names,args,context=None):
res = {}
for record in self.browse(cr,uid,ids,context=context):
res[record.id]={
'total': record.cantidad * record.precioe,
'total1': record.total * record.descuento / 100,
'total2': record.total - record.total1,
'iva': record.total2 * 16 / 100,
'gran_total': record.iva + record.total2,
}
return res
and
'cantidad': fields.integer('Cantidad', multi='calc'),
'precioe': fields.float('Costo', multi='calc'),
#'precio_equipo': fields.related('equipo', 'precio', string='Precio', type='float', readonly=True),
'total': fields.function(_total, type='float', method=True, string='Total', store=True, multi='calc'),
'descuento': fields.integer('Descuento', multi='calc'),
'total1': fields.function(_total, type='float', method=True, string='Total descuento', store=True, multi='calc'),
'total2': fields.function(_total, type='float', method=True, string='subtotal', store=True, multi='calc'),
'iva': fields.function(_total, type='float', method=True, string='IVA', store=True, multi='calc'),
'gran_total': fields.function(_total, type='float', method=True, string='Total', store=True, multi='calc'),
}
and i can only calculate the first total, and the others values appear in 0. What im i doing wrong?
Upvotes: 0
Views: 204
Reputation: 14746
You have to manage this code by using two way. 1) Make your code that is not used any function field to calculate for any other functional field as like below.
def _total(self,cr,uid,ids,field_names,args,context=None):
res = {}
for record in self.browse(cr,uid,ids,context=context):
total = record.cantidad * record.precioe
total1 = total * record.descuento / 100
total2 = total - record.total1
iva = total2 * 16 / 100
gran_total = iva + total2
res[record.id]={
'total':total,
'total1': total1,
'total2': total2,
'iva': iva,
'gran_total': gran_total,
}
return res
You will get perfect data for each of the fields.
Inside your code when system is going to get total
while calculation of the total1
system always get '0' (zero) because its value is still not set.
2) Make all the function different and give the appropriate priority to call each of them.
Thats it.
Upvotes: 1