Skip to Content
Menu
This question has been flagged
1 Reply
720 Views

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

Avatar
Discard
Best Answer

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("")

Avatar
Discard