İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
6607 Görünümler

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
Vazgeç
En İyi Yanıt
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
Vazgeç
Üretici

Thank You very much :)

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Eyl 15
2807
6
Ara 23
66019
1
Mar 19
10518
2
Şub 25
6887
3
Haz 24
9394