码迷,mamicode.com
首页 > 其他好文 > 详细

odoo Reference 选择model 然后选择record

时间:2020-01-09 17:09:40      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:name   script   src   selection   format   and   动规   records   api   

技术图片

class ActivityRules(models.Model):
    _description = '活动规则'
    _name = 'activity.rules'
    # 值越小优先级越高
    rank = fields.Integer(string='折扣优先级')
    rule = fields.Reference(selection='_select_rules')

    @api.model
    def _select_rules(self):
        records = self.env['ir.model'].search([
            ('model', 'like', 'activity.rule.%')
        ])
        return [(record.model, record.name) for record in records]


class ActivityRuleReduce(models.Model):
    _description = '满减规则'
    _name = 'activity.rule.reduce'

    satisfy_money = fields.Float(string='满足金额')
    reduce_money = fields.Float(string='减少金额')
    name = fields.Char(string='满减名', readonly=True, compute='_get_name', store=True)

    @api.depends('reduce_money', 'satisfy_money')
    def _get_name(self):
        for record in self:
            if record.satisfy_money and record.reduce_money:
                record.name = '满{}元 减{}元'.format(record.satisfy_money, record.reduce_money)

odoo Reference 选择model 然后选择record

标签:name   script   src   selection   format   and   动规   records   api   

原文地址:https://www.cnblogs.com/edhg/p/12172373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!