Hi,
Please try this code:
In this, we have created a new field that works according to the given compute function. It will traverse the lines of the notebook and calculate the quantity. Then this field can be used directly in the tree view.
Python Code
class StockPicking(models.Model):
_inherit = 'stock.picking'
total_quantity_done = fields.Float(
'Total Quantity Done', compute='_total_quantity_done_compute',
digits='Product Unit of Measure')
@api.depends('move_line_ids_without_package.qty_done',
'move_line_ids.product_uom_id')
def _total_quantity_done_compute(self):
for rec in self:
rec.total_quantity_done = 0.00
if rec.move_line_ids_without_package:
for line_ids in rec.move_line_ids_without_package:
rec.total_quantity_done += line_ids.qty_done
XML Code
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock_picking_view_form" model="ir.ui.view">
<field name="name">stock.picking.view.form.inherit.mrp_ext</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='backorder_id']"
position="after">
<field name="total_quantity_done"/>
</xpath>
</field>
</record>
<record id="stock_picking_view_tree" model="ir.ui.view">
<field name="name">stock.picking.view.tree.inherit.mrp_ext</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='origin']"
position="after">
<field name="total_quantity_done"/>
</xpath>
</field>
</record>
</odoo>
Regards
use studio app