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

in hr.employee i have added a field x_loan_applicable_amount as computed field, below is the compute method, but its not working. i want to calculate amount columns in 2 models hr.payslip.input and hr.payslip.line below is for one just to test but i want it to plus both amount columns.

def compute_loan_applicable_amount(self):
    # self : model shift
    input_amt = self.env['hr.payslip.input']
    for rec in self:
        applicable_amount = 0
        input_ids = input_amt.search([('payslip_id.employee_id', '=', rec.id)])
        if input_ids:
            for inputs in input_ids:
                # amount = payment amount
                applicable_amount += inputs.amount
        rec['x_loan_applicable_amount'] = applicable_amount

please help.

regards


Ảnh đại diện
Huỷ bỏ
Tác giả

anybody knows how to resolve this problem?

Tác giả

please somebody help...

Have you written "api.depends" on your compute method??

Tác giả

i am working through Settings -> Technical and it ask for Dependcies, i have given 'name' field here which will works after editing in this field and not automatically when loading form / new record.

I don't get what are you trying to tell.

Tác giả

i am working enabling Developer mode (localhos:8017/web?debug=1)

in Settings now it has another Menu which is Technical when click this Menu is shows us various options, i selected Models and select Employee model to add Compute method on a field (x_loan_applicable_amount) , in Dependencies it required to add field(s) , i given a field name here.

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

Hello Smith.John45

try below code once

def compute_loan_applicable_amount(self):

    # self: model shift

    input_amt = self.env['hr.payslip.input']

    for rec in self:

        applicable_amount = sum(input_amt.search([('payslip_id.employee_id', '=', rec.id)]).mapped('amount'))

        rec['x_loan_applicable_amount'] = applicable_amount

Best Regards,
Shakti

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks, but it still not working... how i can see the values in log to verify? i am using Settings -> Technical -> Models when i used print() function, it says print is undefined, also raise UserError() is not working.
.

Tác giả

i didn't marked it as Answer... within 20 minutes without any feedback?

Tác giả

@Shaktisinh Jadav (shj) thanks to re-open it.

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

Do this

rec.write({"x_loan_applicable_amount" : applicable_amount})
Ảnh đại diện
Huỷ bỏ
Tác giả

no, its not working... how i can check the value of rec.id, i am working in Odoo17, using Developer mode on, Settings -> Technical -> Models

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

Hi Smith,

Please try;
rec.x_loan_applicable_amount = applicable_amount
instead of;
​rec['x_loan_applicable_amount'] = applicable_amount


Thanks.

Ảnh đại diện
Huỷ bỏ
Tác giả

nop, this is not working that's why i changed to what i have wrote in my compute method.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 23
8303
3
thg 12 24
6538
0
thg 1 24
1817
2
thg 6 23
4653
1
thg 5 23
3513