mirror of
https://gitlab.com/sonalarora/tra_backend.git
synced 2026-01-03 06:32:52 +02:00
add new module
This commit is contained in:
3
hr_payroll_community/tests/__init__.py
Normal file
3
hr_payroll_community/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import test_payslip_flow
|
||||
50
hr_payroll_community/tests/common.py
Normal file
50
hr_payroll_community/tests/common.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from odoo.fields import Date
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestPayslipBase(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPayslipBase, self).setUp()
|
||||
|
||||
# Some salary rules references
|
||||
self.hra_rule_id = self.ref('hr_payroll_community.hr_salary_rule_houserentallowance1')
|
||||
self.conv_rule_id = self.ref('hr_payroll_community.hr_salary_rule_convanceallowance1')
|
||||
self.prof_tax_rule_id = self.ref('hr_payroll_community.hr_salary_rule_professionaltax1')
|
||||
self.pf_rule_id = self.ref('hr_payroll_community.hr_salary_rule_providentfund1')
|
||||
self.mv_rule_id = self.ref('hr_payroll_community.hr_salary_rule_meal_voucher')
|
||||
self.comm_rule_id = self.ref('hr_payroll_community.hr_salary_rule_sales_commission')
|
||||
|
||||
# I create a new employee "Richard"
|
||||
self.richard_emp = self.env['hr.employee'].create({
|
||||
'name': 'Richard',
|
||||
'gender': 'male',
|
||||
'birthday': '1984-05-01',
|
||||
'country_id': self.ref('base.be'),
|
||||
'department_id': self.ref('hr.dep_rd')
|
||||
})
|
||||
|
||||
# I create a salary structure for "Software Developer"
|
||||
self.developer_pay_structure = self.env['hr.payroll.structure'].create({
|
||||
'name': 'Salary Structure for Software Developer',
|
||||
'code': 'SD',
|
||||
'company_id': self.ref('base.main_company'),
|
||||
'rule_ids': [(4, self.hra_rule_id), (4, self.conv_rule_id),
|
||||
(4, self.prof_tax_rule_id), (4, self.pf_rule_id),
|
||||
(4, self.mv_rule_id), (4, self.comm_rule_id)],
|
||||
})
|
||||
|
||||
# I create a contract for "Richard"
|
||||
self.env['hr.contract'].create({
|
||||
'date_end': Date.to_string((datetime.now() + timedelta(days=365))),
|
||||
'date_start': Date.today(),
|
||||
'name': 'Contract for Richard',
|
||||
'wage': 5000.0,
|
||||
'type_id': self.ref('hr_contract.hr_contract_type_emp'),
|
||||
'employee_id': self.richard_emp.id,
|
||||
'struct_id': self.developer_pay_structure.id,
|
||||
})
|
||||
78
hr_payroll_community/tests/test_payslip_flow.py
Normal file
78
hr_payroll_community/tests/test_payslip_flow.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
from odoo.tools import config, test_reports
|
||||
from odoo.addons.hr_payroll_community.tests.common import TestPayslipBase
|
||||
|
||||
|
||||
class TestPayslipFlow(TestPayslipBase):
|
||||
|
||||
def test_00_payslip_flow(self):
|
||||
""" Testing payslip flow and report printing """
|
||||
# I create an employee Payslip
|
||||
richard_payslip = self.env['hr.payslip'].create({
|
||||
'name': 'Payslip of Richard',
|
||||
'employee_id': self.richard_emp.id
|
||||
})
|
||||
|
||||
payslip_input = self.env['hr.payslip.input'].search([('payslip_id', '=', richard_payslip.id)])
|
||||
# I assign the amount to Input data
|
||||
payslip_input.write({'amount': 5.0})
|
||||
|
||||
# I verify the payslip is in draft state
|
||||
self.assertEqual(richard_payslip.state, 'draft', 'State not changed!')
|
||||
|
||||
context = {
|
||||
"lang": "en_US", "tz": False, "active_model": "ir.ui.menu",
|
||||
"department_id": False, "section_id": False,
|
||||
"active_ids": [self.ref("hr_payroll_community.menu_department_tree")],
|
||||
"active_id": self.ref("hr_payroll_community.menu_department_tree")
|
||||
}
|
||||
# I click on 'Compute Sheet' button on payslip
|
||||
richard_payslip.with_context(context).compute_sheet()
|
||||
|
||||
# Then I click on the 'Confirm' button on payslip
|
||||
richard_payslip.action_payslip_done()
|
||||
|
||||
# I verify that the payslip is in done state
|
||||
self.assertEqual(richard_payslip.state, 'done', 'State not changed!')
|
||||
|
||||
# I want to check refund payslip so I click on refund button.
|
||||
richard_payslip.refund_sheet()
|
||||
|
||||
# I check on new payslip Credit Note is checked or not.
|
||||
payslip_refund = self.env['hr.payslip'].search([('name', 'like', 'Refund: '+ richard_payslip.name), ('credit_note', '=', True)])
|
||||
self.assertTrue(bool(payslip_refund), "Payslip not refunded!")
|
||||
|
||||
# I want to generate a payslip from Payslip run.
|
||||
payslip_run = self.env['hr.payslip.run'].create({
|
||||
'date_end': '2011-09-30',
|
||||
'date_start': '2011-09-01',
|
||||
'name': 'Payslip for Employee'
|
||||
})
|
||||
|
||||
# I create record for generating the payslip for this Payslip run.
|
||||
|
||||
payslip_employee = self.env['hr.payslip.employees'].create({
|
||||
'employee_ids': [(4, self.richard_emp.id)]
|
||||
})
|
||||
|
||||
# I generate the payslip by clicking on Generat button wizard.
|
||||
payslip_employee.with_context(active_id=payslip_run.id).compute_sheet()
|
||||
|
||||
# I open Contribution Register and from there I print the Payslip Lines report.
|
||||
self.env['payslip.lines.contribution.register'].create({
|
||||
'date_from': '2011-09-30',
|
||||
'date_to': '2011-09-01'
|
||||
})
|
||||
|
||||
# I print the payslip report
|
||||
data, data_format = self.env.ref('hr_payroll_community.action_report_payslip').render(richard_payslip.ids)
|
||||
|
||||
# I print the payslip details report
|
||||
data, data_format = self.env.ref('hr_payroll_community.payslip_details_report').render(richard_payslip.ids)
|
||||
|
||||
# I print the contribution register report
|
||||
context = {'model': 'hr.contribution.register', 'active_ids': [self.ref('hr_payroll_community.hr_houserent_register')]}
|
||||
test_reports.try_report_action(self.env.cr, self.env.uid, 'action_payslip_lines_contribution_register', context=context, our_module='hr_payroll_community')
|
||||
Reference in New Issue
Block a user