コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6050 ビュー

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!

アバター
破棄

use studio app

最善の回答

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

アバター
破棄

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.

関連投稿 返信 ビュー 活動
2
3月 23
3617
2
3月 18
4683
0
2月 25
1051
3
8月 22
11849
2
2月 19
4067