Skip to Content
Menu
This question has been flagged
1 Reply
5977 Views

Hello,

 I want to add a field which is found in the inventory overview delivery orders, if you open a form (stock.picking) you will find detailed operation notebook page which contains the quantity done field. I want to add this field to the tree view of (stock.picking).


I tried to add it to the view but it says that it doesn't contain this field. Is there any solution. Waiting for a reply!


Thanks in advance!

Avatar
Discard

use studio app

Best Answer

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

Avatar
Discard

Hi,
Consider the below case also
‘quantity_done’ field is defined in ‘stock.move’ and odoo connects through relation field (‘one2many
So you cannot define the field in tree view which is not present in ‘stock.picking’ model.
It’s not a good idea to compute the value from ‘stock.move’ to a custom field which is defined in stock.picking because there many have multiple products with done quantities in one2many.

Related Posts Replies Views Activity
2
Mar 23
3581
2
Mar 18
4641
0
Feb 25
1009
3
Aug 22
11807
2
Feb 19
3996