我试着在奥多8中施加一个约束。我已经阅读了它的解释并遵循了示例:
Decorates a constraint checker. Each argument must be a field name used in the check. Invoked on the records on which one of the named fields has been modified. (from https://www.odoo.com/documentation/8.0/reference/orm.html)
This decorator will ensure that decorated function will be called on create, write, unlink operation. If a constraint is met the function should raise a openerp.exceptions.Warning with appropriate message. (from http://odoo-new-api-guide-line.readthedocs.io/en/latest/decorator.html)
但对我来说,这根本不起作用。我为依赖于state
字段的stock.picking
模型设置了一个约束(一开始它依赖于picking_type_id
、state
和{
@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.')
)
问题是,当我创建一个新的拾取时,约束被调用,并且不再调用次数。如果我标记为“待办”、“确认”或“转移”领料,则其状态将更改,但不再调用约束。在
我错过了什么吗?谁能帮帮我吗?在
看起来问题可能与它是一个老式的计算字段有关。使用新样式的api简单地重写
state
字段和stock.picking
模型的_state_get
方法似乎可以解决这个问题,并且约束被称为每个状态更改。在这个解决办法对我有效。在
相关问题 更多 >
编程相关推荐