跳至内容
菜单
此问题已终结
1 回复
6603 查看

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 :)

相关帖文 回复 查看 活动
0
9月 15
2807
6
12月 23
66017
1
3月 19
10518
2
2月 25
6887
3
6月 24
9394