Skip to Content
Menu
This question has been flagged
2 Replies
9042 Views

How can I change the value of a fields.selection in a function? 

def fuse_tickets(self, cr, uid, ids, context=None):    
    active_tickets = context.get('active_tickets')    
    active_tickets = ast.literal_eval(active_tickets)    
    ticket = context.get('ticket')    
    for active in active_tickets:        
        if active != ticket:            
            status = self.pool.get('tickets').browse(cr, uid, active, context=context)            
    ? -->   status.update('value': {'fused', 'fused'}) <-- ?

This is the function that I have created but I can't change the status (that is the fields.selection) to another option that it has defined in the .py

Avatar
Discard
Best Answer

If I get it right, what you want is to assign a new value to that field.


You can modify any field from the model with:


 self.value = 'value_to_assign'

In your function it should be just:

 self.value = 'fused'

In the case of a selection field, you just need to give the value part of the Tuple, not the label.


 



Avatar
Discard
Author

I tried to do that but it doesn't work. def fuse_tickets(self, cr, uid, ids, context=None): active_tickets = context.get('active_tickets') active_tickets = ast.literal_eval(active_tickets) ticket = context.get('ticket') for active in active_tickets: if active != ticket: fused = self.pool.get('tickets').browse(cr, uid, active, context=context) fused.fused= 'fused' My selection field is called 'fused' and the only option that it has is 'fused' Thanks!

Might be a typo, but... fused.fused = 'fused' doesn't seem right. First, it MUST say self, then a dot and then the name of the field: self.value = then you assign the value for the selection as a string.

Author

There, it doesn't seen right, but fused is a variable that get the specific object ***fused = self.pool.get('tickets').browse(cr, uid, active, context=context)*** And then I access to the selection field and I equal to the value *** fused.fused = 'fused' *** Is it wrong?

Best Answer

Hello,

if you want to add a new value, just have to redefine the field with inheritance, adding the values you need, like

state = fields.Selection([ ('draft', 'Draft'), ('sent', 'Quotation Sent'), ('done', 'Done'),('your_value','Your Value') ], 'Status', ......

then you can asign your value, like

self.state='your_value'


Kind Regards,

Juanvi




Avatar
Discard
Related Posts Replies Views Activity
2
Apr 21
3404
1
Mar 21
6960
3
Dec 19
2930
1
Dec 18
1687
2
Oct 18
6478