odoo Reference 选择model 然后选择record

Posted edhg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了odoo Reference 选择model 然后选择record相关的知识,希望对你有一定的参考价值。

技术图片

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的主要内容,如果未能解决你的问题,请参考以下文章

更新:Odoo项目任务标签域

Odoo 防止在 One2many 字段中选择重复记录

odoo10学习笔记十:Actions

odoo 怎么重写模块默认方法

odoo12填坑odoo.addons.base.models.ir_attachment报错

odoo之model参数属性1