This question has been flagged
2 Replies
10361 Views

I'm trying to learn how to get Odoo working for my small business. We are on Odoo Community 13.0

Because we rely on an external shipping calculator and the APIs are not available to us in Odoo Community, I would like to have a calculated field that displays the total order weight, total number of items in the order, and volume on the Sales Order view (and eventually report). 

This is because we manually pre-quote freight charges and it would be handy to not have to hand-calculate this information during quoting.

This field should display the total weight of all items in the sales order, as well as the volume - and additionally display the total count of line items in the order.

I've been able to find out how to make simple calculated fields through the GUI, but I'm not sure how to access the product weight, volume by line item and use that in a calculated field which sums the values.

Can anyone point me in the right direction or give an example?

Avatar
Discard
Best Answer

You would need add a calculated field  in the sales order item (sale.order.line). Make sure to click on Store for the product. 

Here is my code for a similar case: 

for record in self:
record[("x_studio_production_weight")] = record.product_qty * record.x_studio_product_weight

And you have to set a field as depency that trigger the calculation. Quantity should do it.

Then on the order header you need to create  field that sum up all the weight on the sales order line. You might choose to use an automated action for that. That was my choice in a similar case.


Avatar
Discard

hello, I'd like to ask if this code is still valid in odoo 14 or did the names change? I tried using product_qty and product_uom_qty and I still can't get an output as it stays at 0

Author Best Answer

(the forum won't let me comment on answers yet, maybe that should be fixed for follow-ups on questions?)

Based on Lars' answer I was able to get a "line weight" field computed.

I'm not sure I understand how to implement the last part. How do I sum up all the weights of sale order lines now? I'm not sure what an "automated action" is. I'm not on Enterprise Edition so don't have Studio.

Avatar
Discard