Skip to Content
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2268 Представления

 I want to move the fields to a different notebook (or tab) in the view and hide the company field: invoice_policy (Invoice Policy), tic_category_id (TaxCloud Category), company_id (Company). However, I encountered an error, this is applicable to the fields mentions:

When i use "position=replace" the fields:

Element '' cannot be located in parent view

When i call the fields again to their new position:

Field "tic_category_id" does not exist in model "product.product"


Here's my code, i am inheriting the form view in Inventory module:




<record id="view_product" model="ir\.ui\.view\"\>


\ \ \ \ \ \ \ \ \<field\ name=\"name\"\>custom.product.product.form.inherit</field>


       <field name="model">product.product</field>


        <field name="priority" eval="6"/>


        <field name="inherit_id" ref="product.product_normal_form_view" />


        <field name="arch" type="xml">


            <!-- When i do this i don’t encounter an error —>


            <field name="barcode" position="replace"/>


            <!-- When i do this i encounter an error an error —>


            <field name="invoice_policy" position="replace"/>


            <group name="group_general" position="inside">


                <!— No error here whenever i call the field —>


                <field name="barcode"/>


                <!— Error when calling again the invoice_policy, saying that it does not exist in product.product —>


                <field name="invoice_policy"/>


            </group>           


        </field>


    </record>



I'm not sure why these 3 fields are experiencing an error and why i can't use the field again. As much as possible i don't want to use xpath. Although, i tried xpath, i still encountered the error above.


Please help. Thank you so much


Аватар
Отменить

You can visible the invisible field
field name="field_name" invisible="0"/>

Лучший ответ

The error you're encountering when using position="replace" or calling the fields again in a different position is likely due to the fact that these fields are defined within a notebook (page or notebook) in the original view, and you're trying to replace or move them outside of that notebook.

To overcome this issue and move the fields to a different notebook or tab while hiding the company_id field, you can use the following approach:

record id="view_product" model=" rel="ugc">ir.ui.view">
fieldname="name">custom.product.product.form.inherit
field name="model">product.product
field name="priority" eval="6"/>
field name="inherit_id" ref="product.product_normal_form_view" />
field name="arch" type="xml">
data>
!-- Find the notebook/page where the fields are defined -->

xpath expr="//notebook/page[@name='page_general_information']" position="inside">
!-- Remove the company_id field -->
field name="company_id" position="replace">
field name="company_id" invisible="1"/>
/field>
-- Move the fields to a different notebook or tab -->
page string="Custom Tab">
group>
field name="invoice_policy"/>
field name="tic_category_id"/>
/group>
/page>
/xpath>
/data>
/field>
/record>

In the above code, we use an XPath expression to find the notebook (page_general_information) where the fields are defined. Then, we remove the company_id field by replacing it with a hidden version of itself ().

Next, we create a new page (or notebook tab) called "Custom Tab" and move the desired fields (invoice_policy and tic_category_id) inside this new page using the tag.

Аватар
Отменить
Автор

I'm still getting an error. For company id -> ERR: Cannot read properties of undefined (reading 'company_id')

And for moving the invoice_policy and tic_category_id -> ERR: Field "invoice_policy" does not exist in model "product.product"

he invoice_policy and tic_category_id fields might be defined in related models or inherited models.
To resolve these errors and successfully move or hide the fields, you need to find the correct model where these fields are defined and update your code accordingly. Here's an example of how you can modify the code:

record id="view_product" model="ir.ui.view">
field name="name">custom.product.product.form.inherit</field>
field name="model">product.template</field>
field name="priority" eval="6"/>
field name="inherit_id" ref="product.product_template_only_form_view"/>
field name="arch" type="xml">
xpath expr="//page[@name='general_information']" position="inside">
field name="barcode" position="replace"/>
/xpath>
xpath expr="//page[@name='general_information']/group[@name='general_info_group']" position="inside">
field name="invoice_policy" position="replace"/>
field name="tic_category_id" position="replace"/>
/xpath>
/field>
/record>

In this modified code:

The model field is changed to product.template to match the correct model where the fields are defined.

The inherit_id is set to product.product_template_only_form_view to inherit the form view specific to the product.template model.

The <xpath> expressions are adjusted to target the correct locations within the view hierarchy, considering the new model and view.

Автор

sorry, now i'm getting this error -> Field "invoice_policy" does not exist in model "product.template"

apparently it still doesn't exist. this is odoo16v if it helps

model in Odoo 16, you can use the following approach:
record id="view_product_template_form" model="ir.ui.view">
field name="name">custom.product.template.form.inherit</field>
field name="model">product.template</field>
field name="inherit_id" ref="product.product_template_only_form_view"/>
field name="arch" type="xml">
xpath expr="//field[@name='barcode']" position="replace">
!-- Your modified barcode field -->
/xpath>
xpath expr="//field[@name='tic_category_id']" position="replace">
<!-- Your modified tic_category_id field -->
/xpath>
xpath expr="//field[@name='company_id']" position="attributes">
attribute name="invisible">1</attribute>
/xpath>
/field>
/record>
In this example, I have assumed that the barcode and tic_category_id fields exist in the product.template model. You can modify the code inside the <xpath> tags to define the modifications you want to make to these fields.

Make sure to update the model attribute in the <record> tag to match the target model for your customization.

Автор

the fields are now hidden, thank you for that. however, i still can't use invoice_policy and tic_category_id

Автор

Can i use xpath to show the field?

yes,you can

Автор

how can i use xpath to show the invisible field?

Автор

<style type="text/css">
p.p1 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 13.0px 'Helvetica Neue'
}

p.p2 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 13.0px 'Helvetica Neue';
min-height: 15.0px
}
</style>
<style type="text/css">
p.p1 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 11.0px 'Helvetica Neue'
}

p.p2 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 11.0px 'Helvetica Neue';
min-height: 12.0px
}
</style>
<style type="text/css">
p.p1 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 13.0px 'Helvetica Neue'
}

p.p2 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 11.0px 'Helvetica Neue';
min-height: 12.0px
}

p.p3 {
margin: 0.0px 0.0px 0.0px 0.0px;
font: 11.0px 'Helvetica Neue'
}
</style>
<p>&nbsp;&lt;xpath expr=&quot;//field[@name=&apos;invoice_policy&apos;]&quot; position=&quot;attributes&quot;&gt;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;attribute name=&quot;invisible&quot;&gt;0&lt;/attribute&gt;</p>
<p>&lt;/xpath&gt;</p>

This code doesn't display the invoice_policy

Автор

i need to use xpath instead of field since i am having an error that the field doesnt exist

xpath expr="//field[@name='invoice_policy']" position="attributes">
attribute name="invisible">0</attribute>
/xpath>

Related Posts Ответы Просмотры Активность
1
мая 20
1926
2
авг. 22
7485
1
февр. 24
1192
2
июн. 23
2061
1
июн. 23
2924