【发布时间】:2016-11-02 10:47:18
【问题描述】:
我正在尝试在 Odoo 8 中应用约束。我已阅读其解释并遵循示例:
装饰一个约束检查器。每个参数必须是一个字段名 在检查中使用。调用其中一个命名的记录 字段已被修改。 (来自https://www.odoo.com/documentation/8.0/reference/orm.html)
这个装饰器将确保被装饰的函数会被调用 创建、写入、取消链接操作。如果满足约束,则函数 应该使用适当的消息引发 openerp.exceptions.Warning。 (来自http://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html)
但在我的情况下它根本不起作用。我为stock.picking 模型做了一个约束,它依赖于state 字段(一开始它依赖于picking_type_id、state 和move_lines 字段,但为了简化问题我改变了它):
@api.one
@api.constrains('state')
def _check_lot_in_outgoing_picking(self):
_logger.info('MY CONSTRAINT IS CALLED')
if self.picking_type_id.code == 'outgoing' and \
self.state not in ['draft', 'cancel'] and \
any(not move.restrict_lot_id for move in self.move_lines):
raise ValidationError(
_('The lot is mandatory in outgoing pickings.')
)
问题是当我创建一个新的拾取时会调用约束并且不再调用。如果我标记为做、确认或转移拣货,它的状态会改变,但不再调用约束。
我有什么想念的吗?谁能帮帮我?
【问题讨论】:
-
用工作流函数设置约束
标签: python xml python-2.7 odoo-8 odoo