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

Hello

I need to make a call to a function in the payslip object, named, for example, salaryfunction:

class HrNicPaySlip(models.Model):
    _inherit = 'hr.payslip'

    @api.multi
    def salaryfunction(self):
       return 100.00

I need to call this function from the salary of type python code calculation rule, like this:

result = payslip.salaryfunction()

But I get the next error when calculate the pay sheep:

Wrong python code defined for salary rule

In the log the error is:

ValueError: : "'float' object is not callable" while evaluating u'result = payslip.salaryfunction()'

Could you please help with that? the version of the odoo is 10 and 11

I searched about some similar issue but without success

Thank you

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

Hello

I finally solved my problem, after read all the code of the payslip model.

The payslip object used in the salary rule has a env variable reference, so the correct way to call a function of other model class is below (according to my example):

result = payslip.env['hr.payslip'].salaryfunction()

The payslip object used inner the salary rule is not the same as the hr.payslip model class.

I hope this works to another dude

Ảnh đại diện
Huỷ bỏ

Hello Garcia, which version of Odoo?

Câu trả lời hay nhất

how i call the function defined in the same model means if the function is defined in the hr.salary.rule how i call in python

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 9 19
6635
0
thg 11 17
4022
1
thg 9 17
5875
0
thg 3 25
1323
4
thg 4 24
174176