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

I have an onchange function that creates an order line on the sales order, which fires when I put a discount value in the global_discount_rate field. The function is:

@api.onchange('global_discount_rate', 'global_discount_type')
def calculate_discount(self):

I need to call this onchange function from a function that I am attaching to a button in the same view. But I don't know the correct way to do it. I tried the following:
Attemp 1:

def create_line(self):
...
    self.calculate_discount()

Attemp 2:

def create_line(self):
...
linevals = {
'global_discount_rate': disc,
'global_discount_type': self.global_discount_type
}
line = self.env['sale.order'].new(self)
line.calculate_discount()
linevals = line._convert_to_write(line._cache)

Neither creates the line I need in the sales order











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

Hi,
You can call the function from anywhere using it’s object. The onchange function calculate_discount() is defined in ‘sale.order’, then you can call it with a sale.order object. In your code, if the self is contain an object of sale.order then you can call it like this:
self.calculate_discount()

And if there's an another field order_id which is stored sale order object then
self.order_id.calculate_discount()

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 20
7686
3
thg 1 18
5596
1
thg 7 25
2520
2
thg 12 24
21129
0
thg 9 24
1021