Odoo Help


Condition IF [Closed]

on 2/4/15, 10:43 PM 891 views

The Question has been closed

on 01/21/2016 23:16:02

i have methode below, i want if program_subsidi_id have used in dealer_sale_order_id all field Readonly=True and if program_subsidi_id haven't used in dealer_sale_order_id just field end date can edit. please give me a right code,,thanks before

    def wtc_perpanjang_periode(self, cr, uid, ids, context=None):    
            val = self.browse(cr, uid, ids)      
            so = self.pool.get('dealer.sale.order').browse(cr,uid,ids ,context=context)
            for x in so.dealer_sale_order_line.discount_line:
                so_search = so.search(cr,uid,[
                so_browse = so.browse(cr,uid,so_search)
                if not so_search:
                    return {'readonly': {'branch_id':True, 'division':True, 'name':True,'date_start':True,'date_end':True, 'keterangan':True,'instansi_id':True,'tipe_subsidi':True,'tipe_subsidi':True,'account_diskon':True,'program_subsidi_line':True,'partner_ref':True }}                   
                if so_search :
                    self.write(cr, uid, ids , {'state':'editable'})                                           
            return True

On 2/5/15, 12:45 AM

If you want to manipulate the view, you need to do it via attrs or on_change.  I would suggest that you create a function field that checks (and return boolean value) whether program_subsidi_id have been used in dealer_sale_order_id.  Include that field in the view and then use it in the view's attrs for the end date field: attrs="{'readonly': [('program_subsidi_id_in_dealer_sale_order_id_field', '=', True)]}".  The rest of the field should have readonly set to 1.

I can't see whether the program_subsidi_id can be changed (if I take the assumption from your first statement, it seems that it is also readonly).  But if program_subsidi_id is editable, you need to implement on_change on this field to re-calculate the value of the function field.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/4/15, 10:43 PM
Seen: 891 times
Last updated: 1/21/16, 11:16 PM