콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I am new to odoo and I have a customer who sells different products where some products have custom fields, we need to show those fields optionally and hide them from other customers' quotations and invoices, we are using odoo 16 Community version any guidance on how to do that?

아바타
취소
베스트 답변

Hi,

You can set the condition in your xml code:

Create XML files for the views you want to customize.
views/sale_order_view.xml:


<odoo>
    <record id="view_order_form_inherit" model="ir.ui.view" style="color:rgb(56,58,66);background-color:rgb(250,250,250);font-size:11pt;">>
        <field name="name">sale.order.form.inherit</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <field name="custom_field" position="attributes">
                <attribute name="attrs">{'invisible': [('partner_id', '=', you can your domain)]}</attribute>
            </field>
        </field>
    </record>
</odoo>



n the same way, you can set up the account. move views  or you can try this method

Define Custom Fields:

from odoo import models, fields

class Product(models.Model):
_inherit = 'product.product'

custom_field_1 = fields.Char(string='Custom Field 1')
custom_field_2 = fields.Float(string='Custom Field 2')
# Add more custom fields as needed



 Define Access Rights:

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_custom_fields,access.product.custom.fields,model_product_product,base.group_user,1,1,1,1

In this way, you can add the groups with the required conditions

from odoo import API, models

class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    result = super(SaleOrder, self).fields_view_get(
        view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
    )

    if view_type == 'form' and self.env.user.has_group('base.group_user'):
        # Add conditions to show/hide fields based on user groups or other criteria
        result['fields']['custom_field_1']['readonly'] = True

    return result



Add Custom Fields to Quotation/Invoice Views:


<record id="view_sale_order_form_custom" model="ir.ui.view">
    <field name="name">sale.order.form.custom</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <!-- Add custom fields to the view -->
        <field name="custom_field_1" position="after">
            <!-- Additional fields or modifications -->
        </field>
    </field>
</record>


Hope it helps

아바타
취소
관련 게시물 답글 화면 활동
1
2월 24
2028
1
10월 25
6009
4
8월 24
2539
4
5월 24
5656
1
4월 23
2151