Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to make a field readonly from a function? or Can we call a function on readonly attribute like "readonly="function_name" in odoo9?

By
Sebin Siby
on 9/8/16, 9:48 AM 268 views

I want to make the "Pricelist" and "Payment Term" readonly if pricelist and payment term is set for the customer in sale order form.

It should be done on onchange of the customer field how can I do this in odoo9?

Is it possible to call a function on readonly attribute like following?


field_name = fields.Many2one('related_model', 'label', readonly="function_name")


def function_name(self):

     if condition:

         return True

     else:

         return False


0
Divyang Jariwala
On 9/9/16, 2:33 AM

Hello Sebin Siby,

set attrs on pricelist like

attrs="{'readonly': [('partner_id.pricelist_id', '!=', False)]}

set attrs on payment term same as like pricelist field just change payment term field name.

I tried it but it's not working. The states and readonly attribute are set for that field while defining it in .py file. The changes made for readonly attribute from xml is not getting reflected on that field.

Sebin Siby
on 9/9/16, 2:40 AM

Now I need to remove the states and readonly attribute from .py file and defining it in xml.

I tried redefining that field without these attributes but the attributes doesn't chages.

Sebin Siby
on 9/9/16, 2:43 AM

Did you update your module and refresh your web page after you made your changes? Because changes made in the xml are not automatically reflected on the database.

Emanuel Cino
on 9/9/16, 5:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/8/16, 9:48 AM
Seen: 268 times
Last updated: 9/9/16, 2:33 AM