コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
10357 ビュー

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

アバター
破棄
最善の回答

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!

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.

著作者

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?

最善の回答

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




アバター
破棄
関連投稿 返信 ビュー 活動
2
4月 21
4965
1
3月 21
8236
3
12月 19
4207
1
12月 18
2643
2
10月 18
7467