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

Hello there,

On a sale order creation, I want to hide the 'create. option of the field partner_shipping_id. But I want to keep the 'create and edit' option.Is it possible?

So the user will have to edit his new partner on creation.

How to achieve this?


Actual code in my custom inherited view :

<xpath expr="//field[@name='partner_shipping_id']" position="attributes">
    <attribute name="domain">['&amp;',('parent_id','=',partner_id),('type','=','delivery')]</attribute>
    <attribute name="attrs">{'no_create': True}</attribute>
</xpath>


Image :



EDIT #1

The real problem is :

I have a new field on res.partner

partner_territory = fields.Many2one(comodel_name='res.territory', string='Partner\'s territory', required=True)

With the 'Create' option, a new shipping address (partner) is created without respecting the 'required=True' of my new field. The partner is created and the field partner_territory stays empty. Isn't it weird?

With the  'Create and Edit...', a new window opens and the user must fill the field parnter_territory. Fine.


What do you think about this?


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

Many2one widget (default)

Options : Other possible options you can use with this widget.

  • no_quick_create - It will remove Create and edit... option.
  • no_create_edit - It will remove Create "entered text" option.
  • no_create - no_quick_create and no_create_edit combined.
  • no_open - in read mode: do not render as a link.

Example:

<field name="field_name" options="{'no_quick_create': True, 'no_create_edit' : True}"/>

You can refer it from  Here

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

I have found the right way to write it. With this, the 'Create' option is invisible. The 'Create and edit...' is still there.

<xpath expr="//field[@name='partner_shipping_id']" position="attributes">
    <attribute name="domain">['&amp;',('parent_id','=',partner_id),('type','=','delivery')]</attribute>
     <attribute name="options">{'no_quick_create':True}</attribute>
</xpath>


But it doesn't explain to me why the 'Create' option can create a new partner WITHOUT respecting 'Required=True' of a field declaration...


 

Ảnh đại diện
Huỷ bỏ

I have the same problem. "quick_create" can pass the required field defined in the model!

Maybe if you defined the required attribute in form xml like: <field name="name_of_field attrs="{'required':True}"

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

Hi Pascal !

You can write attributes to avoid create and create and edit fields in many2one fields with this code:

Regards,

<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="options">{'no_quick_create':True,'no_create_edit':True}</attribute>
</xpath>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Just replace attrs to options like below

<xpath expr="//field[@name='partner_shipping_id']" position="attributes">
    <attribute name="options">{'no_create': True}</attribute>
</xpath>

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

<xpath expr="//field[@name='partner_shipping_id']" position="attributes">
    <attribute name="options">{'no_create': True}</attribute>
</xpath>

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 12 23
19834
1
thg 8 23
2034
0
thg 9 19
5160
1
thg 7 19
7017
1
thg 3 16
5704