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)
原文地址:https://www.cnblogs.com/edhg/p/12172373.html
时间: 2024-10-13 15:50:22