Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
6678 Ansichten

Suppose, in a custom module, I have fields for:

product_id, stock_location, stock_move, etc

And on another custom module I have a Float field, which will have a quantity, it will represent a fiscal year.


So, before I do any movement, I should check for this Float field, and somehow compare it's data with the product, or products I will be moving (product have a field called 'sale_price' but it could be even a custom Float also on product)


I don't know if I'm explaining myself, but what I want is to compare these fields, and give a constraint to the action, if custom_fiscal Float field has a lower value than the product_price Float one, then show a ValidationError or something like that.


I'm not sure if this scenario could be achievable by using a _constraint or _sql_constraint


Any ideas?


Avatar
Verwerfen
Beste Antwort
Hi kristian,
 
What I can understand from your question is, you have to compare the value of a field on your record with a field in another record.
 
for that, you can create any function.
 
for example, you can call the function on the onchange of your field.
 
Ex:
 
from openerp.exceptions import ValidationError
@api.multi
@api.onchange('your_field')
def function_name(self):
       model_of_the_needed_field = self.env['needed.model'].browse(needed_record_id)
       #now you can compare the value of your field and the othor field.
       if self.your_field == model_of_the_needed_field.other_field:
           raise ValidationError(_("*****You can raise any message here.****"))
Thank you.
Avatar
Verwerfen
Autor

Thank You very much :)

Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Sept. 15
2892
6
Dez. 23
66118
1
März 19
10591
2
Feb. 25
6949
3
Juni 24
9430