【问题标题】:Apply check-box condition for only one row value else show warning in Odoo10仅对一个行值应用复选框条件,否则在 Odoo10 中显示警告
【发布时间】:2017-10-25 09:49:48
【问题描述】:

我有一个 One2many 字段。在这个字段中,我有复选框字段。而且,我已经为复选框选择应用了验证。并且功能工作得很好。现在,当我选择检查时,值将返回,如果未选择,则没有问题。但是,现在我希望如果选中 One2many 字段中的任何行复选框,则返回值,否则显示警告。意味着,整体 One2many 中的单行复选框足以返回值。

我的代码在这里:

@api.multi
def action_salepack_add(self):
    rec = self._context.get('active_ids', [])
    wiz = [q.id for q in self.wizard]
    res_wiz=  []
    #here is check box condition#
    for s in self.wizard:
        if s.check_box==True:
            res_wiz.append(s.id)
    #check-box condition over#
    if rec:
        line_values = {'product_id': self.product_id.id,
                       'wizards': [(6, 0, res_wiz)],
                       }
        sale_order_line = self.env['sale.order.line'].create(line_values)

提前致谢

【问题讨论】:

    标签: python-2.7 for-loop if-statement openerp odoo-10


    【解决方案1】:

    我认为您需要添加约束,返回警告;

    from openerp.exceptions import ValidationError
    
    
        @api.constrains('wizard')  # wizard is the one2many field
        def _check_grade_choisi(self):
            for record in self:
                l = []
                if not any([s.check_box for s in record.wizard]) : #Here i check if all checkbox field is False
                    raise ValidationError("Your warning")
    

    【讨论】:

    • 感谢匿名...!!
    猜你喜欢
    • 2023-03-05
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多