Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6625 Переглядів

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?


Аватар
Відмінити
Найкраща відповідь
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.
Аватар
Відмінити
Автор

Thank You very much :)

Related Posts Відповіді Переглядів Дія
0
вер. 15
2810
6
груд. 23
66026
1
бер. 19
10527
2
лют. 25
6894
3
черв. 24
9396