Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6178 Visualizzazioni

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
Abbandona

use studio app

Risposta migliore

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
Abbandona

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.

Post correlati Risposte Visualizzazioni Attività
2
mar 23
3696
2
mar 18
4739
1
ago 25
1214
3
ago 22
11948
2
feb 19
4153