Skip to Content
Menu
This question has been flagged
5 Replies
4424 Views

Hi guys,


I'm stuck here :


<notebook>
<page string="purchase_inquiry_ids">
<!--This is a One2many field relation-->
<field name="purchase_inquiry_ids" context="{'default_purchase_order_id': active_id}"/>
</page>
</notebook>
 


When I click add an item, the purchase_order_id display the current id but I want to add a readonly="1" attribute to this field. 

I really appreciate your help to resolve this.

Avatar
Discard
Best Answer

Hi,

First, create a new form view for your model where you do all customization needed.

After that use "fields_view_get" for the purchase_inquiry_ids model to return this custom view when your context has "default_purchase_order_id" as a key.

@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
     if view_type == 'form' and self.env.context.get('default_purchase_order_id'):
         view_id = "the_custom_view_id"
     return super(YourClass, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

Best regards.

Avatar
Discard
Author Best Answer

I tried to simplify the code by inherit the default view of the 'purchase_inquiry' and pass an attribute to a specific field but it lead me up to a blind alley.

I was obligated to follow the long way.

I write the view from scratch and there I customize what I need :


<notebook>
<page string="purchase_inquiry_ids">
<!-- <field name="purchase_inquiry_ids" context="{'default_purchase_order_id': active_id}" options="{'always_reload': True}"/> -->
<field name="purchase_inquiry_ids" context="{'default_purchase_order_id': active_id}">
<form string="Demande d'offre Form">
<header>
<button string="Set to draft" type="object" name="draft_progressbar" attrs="{'invisible': [('state', '=', 'draft')]}"/>
<button string="Sent" type="object" name="sent_progressbar" attrs="{'invisible': [('state','=','sent')]}"/>
<button string="Received" type="object" name="received_progressbar" attrs="{'invisible': [('state','=','received')]}"/>
<button string="Accepted" type="object" name="accepted_progressbar" class="oe_highlight" attrs="{'invisible': [('state','=','accepted')]}"/>
<button string="Refused" type="object" name="refused_progressbar" class="oe_highlight" attrs="{'invisible': [('state','=','refused')]}"/>
<button string="Create Command" type="object" name="create_command" class="oe_highlight" attrs="{'invisible': [('state','!=','accepted')]}"/>
<field name="state" widget="statusbar" statusbar_visible="draft, sent, received, accepted, refused"/>
</header>
<sheet>
<group>
<field name="name"/>
<field name="purchase_order_id" readonly="1"/>
<field name="provider_id"/>
<field name="date_inquiry"/>
<field name="datefinal_inquiry"/>
</group>
<group col="6">
<field name="product" placeholder="Product Name"/>
<field name="qte" placeholder="Nbr Emballage"/>
<field name="qte_total_unity" placeholder="Qte Totale"/>
</group>
<notebook>
<page string="Informations">
<group>
<field name="price"/>
</group>
</page>
<page string="Description">
<label for="description" string="Description"/>
<field name="description"/>
</page>
</notebook>
</sheet>
</form>
</field>
</page>
</notebook>



Avatar
Discard
Best Answer

You can give readonly="1" for a one2many field

just add

<field name="purchase_inquiry_ids" readonly="1" context="{'default_purchase_order_id': active_id}"/>


Avatar
Discard
Author

Thank you for your reply Mohamed.

Readonly="1" there disable the possibility to create other record by clicking 'add an item'.

I want to display the popup to create another purchase_inquiry record using the current purchase_order id and I would like in this inherited form the purchase_order_id be disabled or readonly.

I didn't clearly understand what you are trying to say,

but if you want to add some thing to your one2many and make fields in its view readonly try this:

<field name='your_one2many'>

<tree>

<field name='field1_in_the_one2many_model' readonly='1'/>

<field name='field2> readonly='1'/>

</tree>

</field>

Related Posts Replies Views Activity
0
Mar 19
2366
2
Dec 19
1648
0
Nov 18
2263
2
Nov 23
5927
2
May 23
5648