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

Hi,

i have Odoo version 8 ,how can i add a required field in the partner forme in all  application using python and xml ?

thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Python

class ExtendPartner(models.Model):
    _inherit = 'res.partner'

    new_field = fields.Char(string='New field', required=True)

XML:
<odoo>
    <data>
        <record id="some_name" model="ir.ui.view">
            <field name="inherit_id" ref="<NAME OF THE PARTNER VIEW WHERE YOU WANT TO ADD>"/>
            <field model="res.partner"/>
            <field name="arch" type="xml">
                <xpath expr="expath expression to where position the new field" position="after">
                    <field name="new_field"/>
                </xpath>    
            </field>    
        </record>
    </data>
</odoo>
Ảnh đại diện
Huỷ bỏ

Great. If you want to know the description about code [py and xml] than visit: http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

In this everything in detail related to inheritance in odoo.

Hope its helpful for you and others who are newbie in Odoo.

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

XML:

<field name="field_name" string="String" required="1"/>

Python:

name = fields.Char('Name', required=True,)

Dynamically on xml by conditions:

<field name="name"
attrs="{'required': [(domain_condition)]}"/>


Add field on partner form

<record model="ir.ui.view" id="new_id">
<field name="name">partner.view.name</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="20"/>
<field name="arch" type="xml">
        <field name="desired_name" position="after">
            your code here
        </field>
    </field>

Note:- I can't comment on your post.

 name = fields.Char(
        string="Name",                   # Optional label of the field
        compute="_compute_name_custom",  # Transform the fields in computed fields
        store=True,                      # If computed it will store the result
        select=True,                     # Force index on field
        readonly=True,                   # Field will be readonly in views
        inverse="_write_name"            # On update trigger
        required=True,                   # Mandatory field
        translate=True,                  # Translation enable
        help='blabla',                   # Help tooltip text
        company_dependent=True,          # Transform columns to ir.property
        search='_search_function'        # Custom search function mainly used with compute
    )

   # The string key is not mandatory
   # by default it wil use the property name Capitalized

This is the verified code and works perfectly. You should search your code for other errors or paste your logs here.




Ảnh đại diện
Huỷ bỏ
Tác giả

thanks , but it didn't work :(

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 19
3323
0
thg 7 17
3435
2
thg 7 16
3309
2
thg 9 23
5066
12
thg 10 23
36137