2015-05-05 61 views
1

如何cumpute field.Selection ???Odoo新的Api更改onchange字段。選擇

listing_type = fields.Selection(string="Format", selection=[('Chinese', 'Auction'), 
                  ('FixedPriceItem', 'Fixed Price')], required=True) 
listing_duration = fields.Selection([ 
    ('Days_1', '1 days'), 
    ('Days_3', '3 days'), 
    ('Days_5', '5 days'), 
    ('Days_7', '7 days'), 
    ('Days_10', '10 days'), 
    ('Days_30', '30 days'), 
    ('GTC', 'GTC'), 
], string="Duration", required=True, compute='_return_listing_duration') 


@api.one 
@api.depends('listing_type') 
def _return_listing_duration(self): 
    if not self.listing_type: 
     return 
    if self.listing_type == 'Chinese': 
     self.listing_duration.selection = [ 
      ('Days_1', '1 days'), 
      ('Days_3', '3 days'), 
      ('Days_5', '5 days'), 
      ('Days_7', '7 days'), 
      ('Days_10', '10 days') 
     ] 
    elif self.listing_type == 'FixedPriceItem': 
     self.listing_duration.selection = [ 
      ('Days_3', '3 days'), 
      ('Days_5', '5 days'), 
      ('Days_7', '7 days'), 
      ('Days_10', '10 days'), 
      ('Days_30', '30 days'), 
      ('GTC', 'GTC') 
     ] 

我的方法_return_listing_duration很不幸無法正常工作。 _return_listing_duration() - >( 'Days_10','10天)

回答

0

嘗試以下,

@api.multi 
@api.depends('listing_type') 
def _return_listing_duration(self): 
    if not self.listing_type: 
     return 
    if self.listing_type == 'Chinese': 
     self.listing_duration = [ 
      ('Days_1', '1 days'), 
      ('Days_3', '3 days'), 
      ('Days_5', '5 days'), 
      ('Days_7', '7 days'), 
      ('Days_10', '10 days') 
     ] 
    elif self.listing_type == 'FixedPriceItem': 
     self.listing_duration = [ 
      ('Days_3', '3 days'), 
      ('Days_5', '5 days'), 
      ('Days_7', '7 days'), 
      ('Days_10', '10 days'), 
      ('Days_30', '30 days'), 
      ('GTC', 'GTC') 
     ] 
+0

計算fields.Selection似乎是不可能的。我沒有找到任何解決方案來改變選擇取決於其他領域。 –