Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
10819 Lượt xem

I have an object with some _sql_constraints and _constraints. This object is a column of a "parent" object, an one2many field in parent class. I need to execute those constraints and _sql_constraints validations when I save the "child" object, not at the moment of saving parent object. Please any help will be welcome, I need a solution as soon as posible....thanks in advanced!!

pd: Sorry my English.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

the point is that child object is not saved until parent is saved. In order to achieve desired behaviour, you might:

1. Instead of constraints, introduce a check as onchange in validated fields. E.g.

from openerp import exceptions
@api.multi
@api.onchange('field_1','field_2')
def _onchange_field_1(self):
    for object in self:
        if object.field_1 > object.field_2:
             raise exceptions.Warning('NOT GOOD!')

Have a look for a similar example in the 'sale' module, when a partner is changed.


2. Force save of a parent object, when child is saved. It ontradicts Odoo logic! But in the onchange you may add some 'write' function, which launch check of constraints.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 15
5406
1
thg 1 25
1674
@api.constrains Đã xử lý
2
thg 12 23
3410
2
thg 9 22
9416
2
thg 4 22
4443