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

I want to add a field named 'nationality' in the product.template model under the product category field.
I want the nationality field to be only visible when the product category is selected as Services.
how can I achieve this in odoo17 please help me.

                   

 

Thank you

Аватар
Отменить
Лучший ответ

Hi,


You can achieve this requirement by using Odoo's views inheritance mechanism. Here's how you can do it:


1. Define the new field nationality in the product.template model:


from odoo import models, fields
class ProductTemplate(models.Model):
    _inherit = 'product.template'
    nationality = fields.Char(string="Nationality")


2. Override the form view of the product.template model. Create a new XML file (for example, product_template_views.xml) in your custom module and add the following code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_template_form_inherited" model="ir.ui.view">
<field name="name">product.template.form.inherited</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">
<xpath expr="//field[@name='categ_id']" position="after">
<field name="nationality" invisible="type != 'service'"/>

            </xpath>
        </field>
    </record>
</odoo>

After making these changes, update the module and refresh the browser to see the changes. Now, the nationality field should only be visible when the product category is selected as Services.

Regards

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

The code is working when i select the product type as 'service'
I want the nationality field to be only visible when I select the product category as 'All / Saleable / Services'.
Please help me how can I do this

Related Posts Ответы Просмотры Активность
0
февр. 24
1091
5
сент. 21
6900
0
сент. 19
2966
3
февр. 24
12671
0
мар. 15
3848