تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5757 أدوات العرض

Am seeking for your assistance on a slight challenge in view inheritance

There's a tree-view inside a notebook and that would like to add more fields to.

I have already inherited the main-view as shown below but i can't seem to get the new fields on the mentioned tree-view. 


Here's what i have so far and has failed. 
Disclaimer:  Am newbie so go 'hard' on me

        
            <field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<!-- <xpath expr="//notebook/page[2]/tree/field[@name='lot_id']" position="after">-->
<!-- <field name="gross_weight"/>-->
<!-- <field name="tare_weight"/>-->
<!-- <field name="moisture_cont" />-->
<!-- </xpath>-->

<notebook position="inside">
<page string="Detailed Operations" attrs="{'invisible': ['|', ('show_operations', '=', False), ('show_reserved', '=', False)]}">

<xpath expr="page[2]" position="inside">
<field name="move_ids_without_package" position="after">
<xpath expr="//tree/field[@name='lot_id']" position="after">
<field name="gross_weight"/>
<field name="tare_weight"/>
<field name="moisture_cont" />
</xpath>

</field>

</xpath>
</page>

</notebook>
</field>
        
الصورة الرمزية
إهمال
الكاتب أفضل إجابة

After implementing @jack suggestion, i  have an error which. The view can no-longer find the already defined model fields. 

Below is the error.

Note: I have a model file which is inheriting the same model as the view and the 'missing' field is already defined there. 

Advanced apologies if am asking the obvious but apparently, i can't seem to figure this one out

Thanks

 <?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>

<record id="picking_orders_additions" model="ir.ui.view">
<field name="name">liroi_fields.picking_orders_additions</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='move_ids_without_package']/tree[1]" position="inside">
<field name="gross_weight"/>

</xpath>

</field>


</record>

</data>
</odoo>



# -*- coding: utf-8 -*-

from odoo import models, fields


class PickingOrdersFields(models.Model):
_inherit = 'stock.picking'

gross_weight = fields.Float(
string='Gross Weight',
# related='delivery_id.weight',
)
tare_weight = fields.Float(
string='Tare Weight',
# related='delivery_id.weight',
)
moisture_cont = fields.Float(
string='Moisture Content',
# related='delivery_id.weight',
)
الصورة الرمزية
إهمال

Hello,

Just to check is the "gross weight" field defiantly a field which is located in the model "lot_id"?

Could you share the Python code which extends the model?

Thanks,

Another good way to check if the field exists is to go to settings->technical->models and search for the lot_id model. From here you will see all the fields in this model.

الكاتب

Hi Jack,

Please see the edited content for both the view and corresponding .py file

Thanks alot

أفضل إجابة

Hello,

There are quite a few things wrong here, but I will try and help you best I can. Your first attempt (commented) looks promising. We all start somewhere.

Below is an example where you would have a One2many with a student model and you would like to add the last_name field to the tree view (it only has the first_name defined so far). 

If the form view is displayed as something like:

<field name="student_id"> 
    <tree>
        <field name="first_name"/>
    </tree>
</field>

You would inheirt the view like you have done and then add the field using the xpath. The expression would be:

<xpath expr="//field[@name='student_id']/tree[1]" position="inside">
    <field name="last_name"/>
</xpath>

This has added the field last_name from the Student model into the One2many.

I hope this helps if you need anything clarifying feel free to email/comment.

BTW I believe the notepad doesn't really matter as long as you start with //field_name

Thanks, 

الصورة الرمزية
إهمال
الكاتب

Thanks a batch @jack. Let me try and revert

المنشورات ذات الصلة الردود أدوات العرض النشاط
View inheritance تم الحل
1
مارس 20
3418
12
ديسمبر 18
34731
1
يوليو 16
7035
2
مارس 15
5901
1
مارس 15
3682