[MIG] hr_payroll: Converted yml test cases to python unittest.

This commit is contained in:
Ravi Gohil
2016-07-11 10:19:49 +02:00
committed by Yannick Tivisse
parent 018058b0b2
commit ce37ee8bca
5 changed files with 140 additions and 138 deletions
-3
View File
@@ -40,8 +40,5 @@ Generic Payroll system.
'views/report_payslip_templates.xml',
'views/report_payslipdetails_templates.xml',
],
'test': [
'test/payslip.yml',
],
'demo': ['data/hr_payroll_demo.xml'],
}
-135
View File
@@ -1,135 +0,0 @@
-
I test "Payslip" in order to check the hr_payroll module in OpenERP
-
I create a new employee "Richard"
-
!record {model: hr.employee, id: hr_employee_richard0}:
birthday: '1984-05-01'
country_id: base.be
department_id: hr.dep_rd
gender: male
name: Richard
-
I create a salary structure for "Software Developer"
-
!record {model: hr.payroll.structure, id: hr_payroll_structure_softwaredeveloper}:
name: Salary Structure for Software Developer
code: SD
company_id: base.main_company
rule_ids:
- hr_salary_rule_houserentallowance1
- hr_salary_rule_convanceallowance1
- hr_salary_rule_professionaltax1
- hr_salary_rule_providentfund1
- hr_salary_rule_meal_voucher
- hr_salary_rule_sales_commission
-
I create a contract for "Richard"
-
!record {model: hr.contract, id: hr_contract_richard}:
date_end: !eval "(datetime.now() + timedelta(days=365)).strftime('%Y-%m-%d')"
date_start: !eval time.strftime('%Y-%m-%d')
name: Contract for Richard
wage: 5000.0
type_id: hr_contract.hr_contract_type_emp
employee_id: hr_employee_richard0
struct_id: hr_payroll_structure_softwaredeveloper
working_hours: resource.timesheet_group1
-
I create a Employee Payslip
-
!record {model: hr.payslip, id: hr_payslip_0}:
employee_id: hr_payroll.hr_employee_richard0
-
I assign the amount to Input data
-
!python {model: hr.payslip.input}: |
ids = self.search(cr, uid, [('payslip_id', '=', ref("hr_payslip_0"))])
self.write(cr, uid, ids, {'amount': 5.0})
-
I verify the payslip is in draft state
-
!python {model: hr.payslip}: |
payslip_brw=self.browse(cr, uid, ref("hr_payslip_0"))
assert (payslip_brw.state == 'draft'), 'State not changed!'
-
I click on 'Compute Sheet' button on payslip
-
!python {model: hr.payslip}: |
self.compute_sheet(cr, uid, [ref("hr_payslip_0")], {"lang": "en_US", "tz": False,
"active_model": "ir.ui.menu", "department_id": False, "active_ids": [ref("hr_payroll.menu_department_tree")],
"section_id": False, "active_id": ref("hr_payroll.menu_department_tree"),
})
-
Then I click on the 'Confirm' button on payslip
-
!workflow {model: hr.payslip, action: hr_verify_sheet, ref: hr_payslip_0}
-
I verify that the payslip is in done state
-
!python {model: hr.payslip}: |
payslip_brw=self.browse(cr, uid, ref("hr_payslip_0"))
assert(payslip_brw.state == 'done'), 'State not changed!'
-
I want to check refund payslip so I click on refund button.
-
!python {model: hr.payslip}: |
self.refund_sheet(cr, uid, [ref("hr_payslip_0")], None)
-
I check on new payslip Credit Note is checked or not.
-
!python {model: hr.payslip}: |
payslip_obj = self.browse(cr, uid, ref("hr_payslip_0"), None)
payslip_ids = self.search(cr, uid, [('name','like','Refund: '+payslip_obj.name),('credit_note','=',True)], None)
assert payslip_ids, "Payslip not refunded!"
-
I want to generate a payslip from Payslip run.
-
!record {model: hr.payslip.run, id: hr_payslip_run_PayslipforEmployee0}:
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.
-
!record {model: hr.payslip.employees, id: hr_payslip_employees0}:
employee_ids:
- hr_employee_richard0
-
I generate the payslip by clicking on Generat button wizard.
-
!python {model: hr.payslip.employees}: |
self.compute_sheet(cr, uid, [ref('hr_payslip_employees0')], context={'active_id': ref('hr_payslip_run_PayslipforEmployee0')})
-
I open Contribution Register and from there I print the Payslip Lines report.
-
!record {model: payslip.lines.contribution.register, id: payslip_lines_contribution_register0}:
date_from: '2011-09-30'
date_to: '2011-09-01'
-
I print the payslip report
-
!python {model: hr.payslip}: |
import os
import openerp.report
from openerp import tools
data, format = openerp.report.render_report(cr, uid, [ref('hr_payslip_0')], 'hr_payroll.report_payslip', {}, {})
if tools.config['test_report_directory']:
file(os.path.join(tools.config['test_report_directory'], 'hr_payroll-payslip.'+format), 'wb+').write(data)
-
I print the payslip details report
-
!python {model: hr.payslip}: |
import os
import openerp.report
from openerp import tools
data, format = openerp.report.render_report(cr, uid, [ref('hr_payslip_0')], 'hr_payroll.report_payslipdetails', {}, {})
if tools.config['test_report_directory']:
file(os.path.join(tools.config['test_report_directory'], 'hr_payroll-payslipdetails.'+format), 'wb+').write(data)
-
I print the contribution register report
-
!python {model: hr.contribution.register}: |
ctx={'model': 'hr.contribution.register', 'active_ids': [ref('hr_houserent_register')]}
from openerp.tools import test_reports
test_reports.try_report_action(cr, uid, 'action_payslip_lines_contribution_register', context=ctx, our_module='hr_payroll')
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_payslip_flow
+50
View File
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
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.hr_salary_rule_houserentallowance1')
self.conv_rule_id = self.ref('hr_payroll.hr_salary_rule_convanceallowance1')
self.prof_tax_rule_id = self.ref('hr_payroll.hr_salary_rule_professionaltax1')
self.pf_rule_id = self.ref('hr_payroll.hr_salary_rule_providentfund1')
self.mv_rule_id = self.ref('hr_payroll.hr_salary_rule_meal_voucher')
self.comm_rule_id = self.ref('hr_payroll.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, self.conv_rule_id, self.prof_tax_rule_id, self.pf_rule_id, self.mv_rule_id, 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,
'working_hours': self.ref('resource.timesheet_group1')
})
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import os
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.report import render_report
from odoo.tools import config, test_reports
from odoo.addons.hr_payroll.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.menu_department_tree")],
"active_id": self.ref("hr_payroll.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.signal_workflow('hr_verify_sheet')
# 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.ids)]
})
# 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, format = render_report(self.env.cr, self.env.uid, richard_payslip.ids, 'hr_payroll.report_payslip', {}, {})
if config.get('test_report_directory'):
file(os.path.join(config['test_report_directory'], 'hr_payroll-payslip.'+ format), 'wb+').write(data)
# I print the payslip details report
data, format = render_report(self.env.cr, self.env.uid, richard_payslip.ids, 'hr_payroll.report_payslipdetails', {}, {})
if config.get('test_report_directory'):
file(os.path.join(config['test_report_directory'], 'hr_payroll-payslipdetails.'+ format), 'wb+').write(data)
# I print the contribution register report
context = {'model': 'hr.contribution.register', 'active_ids': [self.ref('hr_payroll.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')