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.

0

Change the value of a fields.selection

By
Celia
on 5/23/16, 8:48 AM 364 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

0
Rubén Cabrera
On 5/23/16, 1:58 PM

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.


 



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!

Celia
on 5/24/16, 2:46 AM

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.

Rubén Cabrera
on 5/24/16, 3:26 AM

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?

Celia
on 5/24/16, 4:46 AM
0
Juan Vicente Pascual
On 5/23/16, 9:59 AM

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




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

2 follower(s)

Stats

Asked: 5/23/16, 8:48 AM
Seen: 364 times
Last updated: 5/23/16, 1:58 PM