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

in another project, I used compute field like this on a function and it works. But why this one is not working?

Here is my code :

from openerp import models, fields, api

class PurchaseOrder(models.Model):

_inherit = 'hr.payslip'

gaji_pokok = fields.Integer(string="Gaji Pokok")

t_lembur = fields.Integer(string="Tunjangan Lembur")

t_transportasi = fields.Integer(string="Tunjangan Transportasi")

bonus = fields.Integer(string="Bonus")

jumlah_kerja = fields.Integer(string="Jumlah Jam Kerja")

libur = fields.Integer(string="Cuti")

total_pendapatan = fields.Monetary(compute = '_compute_gaji', readonly=True, string="Total Gaji")

@api.one

@api.depends('gaji_pokok', 't_lembur', 't_transportasi', 'bonus', 'jumlah_kerja', 'libur')

def _compute_gaji(self):

for sal in self:

if sal.gaji_pokok is not False:

sal.total_pendapatan = sal.gaji_pokok + sal.t_lembur + sal.t_transportasi + sal.bonus + sal.jumlah_kerja + sal.libur


Here is my xml (not all the code I show)

<xpath expr="//page[1]" position="after">

<form colspan="4" nolabel="1">

<page string="Pendapatan Karyawan">

<separator string="Pendapatan Karyawan"/>

<group col="4">

<field name="jumlah_kerja"/>

<field name="libur"/>

<field name="gaji_pokok"/>

<field name="t_lembur"/>

<field name="t_transportasi"/>

<field name="bonus"/>

<field name="total_pendapatan"/>

</group>

</page>

</form>

</xpath>


My error message is "field total_pendapatan doesnt exist"

Anyone can help me about this?

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

Hi,

Make sure that the python file is called in the init file .

Tác giả Câu trả lời hay nhất

I've done added hr_payroll and the python file has been called in init file. But till now, it cant work. Do you have any solution about this?

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

In the xml file in the question, can you check whether the model mentioned is right one, or just update the question with full part of that record

Tác giả

Here full part of my xml code

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data>

<record id="view_hr_payslip_inherit_form_extended" model="ir.ui.view">

<field name="name">hr.payslip.inherit.form</field>

<!-- object of the view -->

<field name="model">hr.payslip</field>

<field name="inherit_id" ref="hr_payroll.view_hr_payslip_form" />

<field name="arch" type="xml">

<xpath expr="//page[1]" position="after">

<form colspan="4" nolabel="1">

<page string="Pendapatan Karyawan">

<separator string="Pendapatan Karyawan"/>

<group col="4">

<field name="jumlah_kerja"/>

<field name="libur"/>

<field name="gaji_pokok"/>

<field name="t_lembur"/>

<field name="t_transportasi"/>

<field name="bonus"/>

<field name="total_pendapatan"/>

</group>

</page>

</form>

</xpath>

</field>

</record>

</data>

</openerp>

I dont know what should I do when this error appear. Maybe do you have any solution again?

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

Hello Try this

First Check Your  __manifest__.py Where You Added depends:['hr_payroll']

If exist Than Try on Your terminal path -u all

In Your Compute Method

if sal.gaji_pokok:

    sal.total_pendapatan = sal.gaji_pokok + sal.t_lembur + sal.t_transportasi + sal.bonus +

    sal.jumlah_kerja + sal.libur

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 21
6802
3
thg 7 20
21187
2
thg 1 19
7264
1
thg 12 18
3172
1
thg 7 18
7533