Odoo新Api改变onchange字段。选择

时间:2015-05-05 14:49:04

标签: api orm model odoo

我如何cumpute field.Selection ???

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天')

1 个答案:

答案 0 :(得分: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')
        ]