Reverse domain integrity check


(Maxime Richez) #1

Hi,
Need some advices about the best way to check if a field keep domain rules…

Here’s the case:
In the purchase_request model, there’s a field preferred_quotation_line which is a many2one on supplier_quotation_lines with domain ‘state = received’ and ‘quotation.request=request’
In the quotation_supplier model you can switch in the workflow from state ‘received’ to state ‘rejected’.
But there’s no control if one of your quotation_line is selected as preferred_quotation_line, so you can have a preferred_quotation_line in state ‘rejected’ even if the domain doesn’t allow this state.
I’m aware that’s not possible to automatically check this kind of issue. So i’m intend to make a check when switching state in the workflow but would like to know the best way to implement it (is there any example of such a case ? I see a lot of case checking if there’s an origin but in my case it is just an id)

Is it better to loop over purchase_requests having a preferred_quotation_line and then check if id match to quotation ?
Or search for each quotation_line if there’s a purchase_request having a preferred quotation_line with the same id ?

Thanks!


(Cédric Krier) #2

This sounds like the best option and it has to remove the line from the preferred field.
In case it removes any preferred line, it will be good to notify the user about it.


(Maxime Richez) #3

Or raising a warning/error to remove manually the preferred line to allow to switch state ?


(Jean Cavallo) #4

One easy way would be to manually call _validate on the purchase_requests, since this should trigger domain validations


(Cédric Krier) #5

I do not think it is a good UX. If the user reject a quotation it is because he really does not want to take it. So I think it will be seen as a burden to have to search for all requests linked to it and clear a field to be allowed to reject.