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

In odoo 9, I am able to use this function : 

class payslip_report_pdf(report_sxw.rml_parse):

    _name = 'payslip_report_pdf'

    _description = "Employee Payslips"

 

    def __init__(self, cr, uid, name, context):

        super(payslip_report_pdf, self).__init__(cr, uid, name, context=context)

        self.localcontext.update({

            'payslips': self.get_payslip_data(cr, uid, context=context),

            'get_payslip_lines': self.get_payslip_lines,

            'get_total_by_rule_category': self.get_total_by_rule_category,

            })


    def get_payslip_data(self, cr, uid, context=None):

        retval = {}

        payslip_obj = self.pool.get('hr.payslip')

        payslip_ids = context.get('active_ids')

        payslips = payslip_obj.browse(cr, uid, payslip_ids, context=context)

        for payslip in payslips:

            sen_yr, sen_mon, sen_day = self.pool.get('hr.employee')\

                .get_seniority_ymd(cr, uid, payslip.employee_id.id, context=context)

            seniority = '%dA, %dM, %dJ' % (sen_yr, sen_mon, sen_day)

 

            # Leaves

            leave_obj = self.pool.get('hr.holidays')

            leave_ids = leave_obj.search(cr, uid,

                [('employee_id', '=', payslip.employee_id.id)], context=context)

            leaves = leave_obj.browse(cr, uid, leave_ids, context=context)

            leaves_acquired = sum([x.number_of_days for x in leaves \

                if x.state == 'validate' \

                and x.type == 'add'\

                and x.holiday_status_id.limit == False]) or 0.0

            holidays = [x for x in leaves \

                if x.state == 'validate' \

                and x.type == 'remove' \

                and x.date_from.split()[0] >= payslip.date_from.split()[0] \

                and x.date_to.split()[0] <= payslip.date_to.split()[0]]

            # leaves_taken = sum([x.number_of_days for x in leaves \

            #     if x.state == 'validate' \

            #     and x.type == 'remove'\

            #     and x.holiday_status_id.limit == False])

            leaves_remaining = sum([x.number_of_days for x in leaves\

                if x.state == 'validate' \

                and x.holiday_status_id.limit == False]) or 0.0

 

 

            retval[payslip] = {

                # 'lines': lines,

                'seniority': seniority,

                'leaves_acquired': leaves_acquired,

                # 'leaves_taken': leaves_taken,

                'leaves_remaining': leaves_remaining,

                'holidays': holidays,

            }

            retval[payslip].update(self.get_salarial_data(cr, uid, payslip,

                yearly=False, context=context))

            # Yearly stuff

            jan_1 = payslip.date_from.split('-')[0] + '-01-01'

            slip_end = payslip.date_to.split()[0]

            yr_slip_ids = payslip_obj.search(cr, uid,

                [('employee_id', '=', payslip.employee_id.id),

                ('date_from', '>=', jan_1),

                ('date_to', '<=', slip_end)], context=context)

            yearly_data = dict.fromkeys(['gross_year',

                'salarial_costs_year',

                'patronal_costs_year',

                'net_salary_year',

                'benefits_in_kind_year',

                'worked_hours_year',

                'worked_days_year'], 0)

            for yr_slip in payslip_obj.browse(cr, uid, yr_slip_ids, context=context):

                data = self.get_salarial_data(cr, uid, yr_slip, yearly=True,

                    context=context)

                for key in data.keys():

                    yearly_data[key] += data.get(key, 0)

            retval[payslip].update(yearly_data)

 

        return retval

and i call it in my costum report like this.

<span t-esc="payslips[o]['worked_days']"/>

how can i transform it to use it in odoo 10? Thanks.

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

Hi,

Just check out this Odoo documentation to see how to create a qweb report in v10

https://www.odoo.com/documentation/10.0/reference/reports.html

Thanks

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

Thanks,

I finaly did it. but i have some problem when a try to print the report.

AttributeError: 'int' object has no attribute 'get'

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 19
4241
QWeb report Đã xử lý
1
thg 1 19
4031
1
thg 12 18
2980
1
thg 1 18
6012
0
thg 7 17
4873