Skip to Content
Menu
This question has been flagged
3 Replies
6142 Views

I want to make a sum quantity of PO just like the total amount

what function should I write to get the sum quantity when pressing the update button?

Avatar
Discard

did you mean about sum of "quantity" of products?

Your question is a bit unclear. Please specify with an example.

There will be product of different uom's in PO line,, how can we combine that?? eg: 6 gm and 5 liter and 7 No

Author

I am fixing the uom so I can combine it.

Best Answer

There will be product of different uom's in PO line,, how can we combine that?? eg: 6 gm and 5 liter and 7 No.

If you still want to calculate irrespective of that,, you can use the function

first declare a function and  functional field:-

    def _compute_total(self, cr, uid, ids, name, args, context=None):
        res = {}
        for invoice in self.browse(cr, uid, ids, context=context):
            res[invoice.id] = {
                'amount_total': 0.0,
            }
            for line in invoice.order_line:
                res[invoice.id]['amount_total'] += line.product_qty
        return res

'amount_total': fields.function(_compute_total, string='Total Quantity')

If you want to cosider different Units you can update function like this:-

res[invoice.id]['amount_total'] += line.product_qty / line.product_uom.factor

Avatar
Discard
Author

Thanks for the help. It works when I install the module. However, I still cannot update the value when I press the (update) button. Is there any solution?

can you please it clear?? i cant understand what you meant by " It works when I install the module"

Best Answer

Hey! Can anyone help me how I can add this function using the dev tools?

I want to add all the quantities irrespective of their UoM's. 

Avatar
Discard
thankyou! 

On Fri, Feb 11, 2022 at 7:07 PM Niyas Raphy <niyasraphyk@gmail.com> wrote:
Best Answer

Hi Willie, the sum of quantity may provide wrong information because the quantity depends on the UoM and the product.  For example, what is 1 ltr of milk + 1 jug of milk?  Or what is 1 dozen of apple + 1 dozen of orange?

Technically, however you get the sum of the figures, by adding the  sum="XXXX" in the view's field definition, e.g. <field name="amount_total" sum="Total Amount"/>.

Avatar
Discard