Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
6 Відповіді
42848 Переглядів

Hello there,

Let me explain with an example.

In the sale order model, we have these two fields : note (text) and picking_ids (many2many)

In the form view of the sale order, I would want the field note readonly if all the associated pickings of the sale order are in "confirmed" state.

Actually, the note field is displayed like it in the sale order form view :

<field name="note" class="oe_inline"/>

How could I manage it?


EDIT #1

I would want something like that. But it doesn't work.  :

<field name="note" class="oe_inline" attrs="{'readonly': [('picking_ids.state', '=', 'confirmed')]}" />
Аватар
Відмінити
Автор Найкраща відповідь

Here is our solution for the above example.

Thanks all for your help.


I have defined a new boolean field in the sale.order model:

all_picking_confirmed = fields.Boolean(compute='compute_all_picking_confirmed')

With his function :

def compute_all_picking_confirmed(self):
        for order in self:
            order.all_picking_confirmed = True           
                if order.picking_ids:
                    for picking in order.picking_ids:
                        if picking.state not in ('done'):
                            order.all_picking_confirmed = False
                else:
                    order.all_picking_confirmed = False

And in the view :

<field name="note" attrs="{'readonly':[('all_picking_confirmed','=',True)]}"/>
Аватар
Відмінити
Найкраща відповідь

Salut Pascal,

You have a pretty good example in the OCA (probably many other place but first to came to my mind) partner_contact/partner_firstname, togling the read only if it's not a company

<xpath expr="//field[@name='name']" position="attributes">

                    <attribute name="attrs">{

                        'readonly': [('is_company', '=', False)],

                        'required': [('is_company', '=', True)]

                        }</attribute></xpath>


If it's not a boolean, but a matter of list of items, you can go straight to the if variableliste as per OCA/website_sale demonstrate in in their first view declaration

<t t-if="not quotations">

            <p>There are currently no quotes for your account.</p>

        </t>

        <t t-if="quotations">

            <div class="table-responsive">
            .....

Аватар
Відмінити
Автор

In your example, the field is_company is a boolean. In my example, picking_ids is a many2many field. Don't think they work the same way. More, I need to check in picking_ids.state... Thanks

Автор

Are you really sure that we can use t-if condition in a form view of the backend? I don't manage

Найкраща відповідь

Hi, Pascal Tremblay

     You can use (readonly="1") in field.

Аватар
Відмінити
Автор

I know this. But the field "note" must be readonly ONLY if ALL the pickings (many2many, picking_ids) of the sale order are in "confirmed" state. You give me a way to make the field ALWAYS readonly.

Related Posts Відповіді Переглядів Дія
1
бер. 15
4460
0
бер. 24
3886
1
бер. 24
30694
1
жовт. 15
5609
1
лип. 15
3658