mirror of
https://github.com/bringout/oca-payroll.git
synced 2026-04-19 04:02:01 +02:00
Initial commit: OCA Payroll packages (5 packages)
This commit is contained in:
commit
d19274f581
407 changed files with 214057 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
from . import test_hr_payroll_document
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import base64
|
||||
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tests import common
|
||||
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
|
||||
|
||||
class TestHrPayrollDocument(common.TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestHrPayrollDocument, self).setUp()
|
||||
self.env.user.tz = "Europe/Brussels"
|
||||
self.user_admin = self.env.ref("base.user_admin")
|
||||
|
||||
# Fix Company without country
|
||||
self.env.company.country_id = False
|
||||
|
||||
# Test users to use through the various tests
|
||||
self.user_employee = mail_new_test_user(
|
||||
self.env, login="david", groups="base.group_user"
|
||||
)
|
||||
self.user_employee_id = self.user_employee.id
|
||||
|
||||
# Hr Data
|
||||
self.employee_emp = self.env["hr.employee"].create(
|
||||
{
|
||||
"name": "David Employee",
|
||||
"user_id": self.user_employee_id,
|
||||
"company_id": 1,
|
||||
"identification_id": "30831011V",
|
||||
}
|
||||
)
|
||||
|
||||
with open(
|
||||
get_module_resource("hr_payroll_document", "tests", "test.pdf"), "rb"
|
||||
) as pdf_file:
|
||||
encoded_string = base64.b64encode(pdf_file.read())
|
||||
ir_values = {
|
||||
"name": "test",
|
||||
"type": "binary",
|
||||
"datas": encoded_string,
|
||||
"store_fname": encoded_string,
|
||||
"res_model": "payroll.management.wizard",
|
||||
"res_id": 1,
|
||||
}
|
||||
self.attachment = self.env["ir.attachment"].create(ir_values)
|
||||
self.subject = "January"
|
||||
self.wizard = self.env["payroll.management.wizard"].create(
|
||||
{"payrolls": [self.attachment.id], "subject": self.subject}
|
||||
)
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,107 @@
|
|||
import base64
|
||||
|
||||
from odoo import _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.modules.module import get_module_resource
|
||||
|
||||
from odoo.addons.hr_payroll_document.tests.common import TestHrPayrollDocument
|
||||
|
||||
|
||||
class TestHRPayrollDocument(TestHrPayrollDocument):
|
||||
def setUp(self, *args, **kwargs):
|
||||
super().setUp(*args, **kwargs)
|
||||
|
||||
def fill_company_id(self):
|
||||
self.env.company.country_id = self.env["res.country"].search(
|
||||
[("name", "=", "Spain")]
|
||||
)
|
||||
|
||||
def test_extension_error(self):
|
||||
with open(
|
||||
get_module_resource("hr_payroll_document", "tests", "test.docx"), "rb"
|
||||
) as pdf_file:
|
||||
encoded_string = base64.b64encode(pdf_file.read())
|
||||
ir_values = {
|
||||
"name": "test",
|
||||
"type": "binary",
|
||||
"datas": encoded_string,
|
||||
"store_fname": encoded_string,
|
||||
"res_model": "payroll.management.wizard",
|
||||
"res_id": 1,
|
||||
}
|
||||
self.attachment = self.env["ir.attachment"].create(ir_values)
|
||||
self.subject = "January"
|
||||
self.wizard = self.env["payroll.management.wizard"].create(
|
||||
{"payrolls": [self.attachment.id], "subject": self.subject}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.wizard.send_payrolls()
|
||||
|
||||
def test_company_id_required(self):
|
||||
with self.assertRaises(UserError):
|
||||
self.wizard.send_payrolls()
|
||||
|
||||
def test_employee_vat_not_valid(self):
|
||||
self.fill_company_id()
|
||||
with self.assertRaises(ValidationError):
|
||||
employees = self.env["hr.employee"].search([])
|
||||
for employee in employees:
|
||||
if not employee.identification_id:
|
||||
employee.identification_id = "XXXXXXX"
|
||||
|
||||
def test_one_employee_not_found(self):
|
||||
self.fill_company_id()
|
||||
self.env["hr.employee"].search([("id", "=", 1)]).identification_id = "37936636E"
|
||||
self.assertEqual(
|
||||
self.wizard.send_payrolls(),
|
||||
{
|
||||
"type": "ir.actions.client",
|
||||
"tag": "display_notification",
|
||||
"params": {
|
||||
"title": _("Employees not found"),
|
||||
"message": _("IDs whose employee has not been found: ")
|
||||
+ "51000278D",
|
||||
"sticky": True,
|
||||
"type": "warning",
|
||||
"next": {
|
||||
"name": _("Payrolls sent"),
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "hr.employee",
|
||||
"views": [
|
||||
(
|
||||
self.env.ref("hr.hr_employee_public_view_kanban").id,
|
||||
"list",
|
||||
)
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
def test_send_payrolls_correctly(self):
|
||||
self.fill_company_id()
|
||||
self.env["hr.employee"].search([("id", "=", 1)]).identification_id = "51000278D"
|
||||
self.assertEqual(
|
||||
self.wizard.send_payrolls(),
|
||||
{
|
||||
"type": "ir.actions.client",
|
||||
"tag": "display_notification",
|
||||
"params": {
|
||||
"title": _("Payrolls sent"),
|
||||
"message": _("Payrolls sent to employees correctly"),
|
||||
"sticky": False,
|
||||
"type": "success",
|
||||
"next": {
|
||||
"name": _("Payrolls sent"),
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "hr.employee",
|
||||
"views": [
|
||||
(
|
||||
self.env.ref("hr.hr_employee_public_view_kanban").id,
|
||||
"list",
|
||||
)
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue