Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6163 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ

use studio app

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
Many2many fields Đã xử lý
2
thg 3 23
3690
2
thg 3 18
4723
1
thg 8 25
1202
3
thg 8 22
11943
2
thg 2 19
4152