Reputation: 3907
I need to count and show the number of items, of for example a purchase.order.line
and show them on an integer
type field.
For example in a purchase.order
i add 13 items, or products; this field, will store and then show outside the purchase.order.line
the quantity of items of this purchase.
I've looked in stackexchange, and in the openerp books, but no luck in finding a an example of such a function.
Any module or existing functon should i look for?
Thanks in advance
Upvotes: 0
Views: 1066
Reputation: 2499
I am not completely sure what you are asking. Do you mean that if you have a purchase order with 13 lines, you want a field on the purchase order to show the sum of the quantity fields on the 13 order lines?
If so, you need to extend the purchase.order model and add a functional field that will iterate through the order lines and total the quantity.
Your column would be:
'total_quantity': fields.function(_get_total_quantity, type='float', method = True, string = 'Total Quantity', readonly = True),
Your method would be:
def _get_total_quantity(self, cr, uid, ids, field, args, context = None):
res = {}
for po in self.browse(cr, uid, ids, context = context):
res[po.id] = sum([x.quantity for x in po.order_line])
return res
Please check that the name of the one2many on purchase.order for the purchase order lines is "order_line". I am doing this from memory and I can't remember the column name.
Upvotes: 1