跳至內容
選單
此問題已被標幟
1 回覆
1057 瀏覽次數

so i have a field named "delay_id" in purchase order line and the field is editable and the value cannot surpass field value "delay" in product supplier info, i tried this code

@api.constrains('delay_id')    

    def_check_delay(self):        

        forrecordinself:            

            dly = self.env['product.supplierinfo'].search([('delay', ',record.delay_id),('id', '=',record.id)])            

        ifdly:                

            raise ValidationError("")

but the value can still surpass the value in product supplier info .

the "delay" field is from another module

頭像
捨棄
最佳答案

You need to get the delay for each product in purchase line for the same vendor selected in the PO header and then compare the values. The delay_id should be an integer to compare it with delay from product supplier info.

Please check the below:


@api.constrains('delay_id')
def _check_delay(self):
for record in self:
dly = self.env['product.supplierinfo'].search(
[('name', '=', record.order_id.id), ('product_tmpl_id.id', '=', record.product_id.product_tmpl_id.id)])
if dly:
if record.delay_id > dly.delay:
raise ValidationError("")

頭像
捨棄