diff --git a/l10n_ca_hr_payroll/data/federal.xml b/l10n_ca_hr_payroll/data/federal.xml index 9d400310..08cee3b0 100644 --- a/l10n_ca_hr_payroll/data/federal.xml +++ b/l10n_ca_hr_payroll/data/federal.xml @@ -27,12 +27,6 @@ - - EE: Federal Income Tax Withholding - EE_CA_FIT - - - EE: Canada Pension Plan EE_CA_CPP @@ -45,7 +39,41 @@ + + EE: Federal Income Tax Withholding + EE_CA_FIT + + + + + + + + EE: Canada Pension Plan + EE_CA_CPP + python + result, _ = ca_cpp(payslip, categories, worked_days, inputs) + code + result, result_rate = ca_cpp(payslip, categories, worked_days, inputs) + + + + + + + + + EE: CA Employment Insurance + EE_CA_EI + python + result, _ = ca_ei(payslip, categories, worked_days, inputs) + code + result, result_rate = ca_ei(payslip, categories, worked_days, inputs) + + + + @@ -60,7 +88,4 @@ - - - \ No newline at end of file diff --git a/l10n_ca_hr_payroll/models/federal/ca_cpp.py b/l10n_ca_hr_payroll/models/federal/ca_cpp.py index 0870d892..53d88fb6 100644 --- a/l10n_ca_hr_payroll/models/federal/ca_cpp.py +++ b/l10n_ca_hr_payroll/models/federal/ca_cpp.py @@ -1,5 +1,11 @@ # Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +def ca_cpp(payslip, categories, worked_days, inputs): + if payslip.contract_id.ca_payroll_config_value('is_cpp_exempt'): + return 0.0, 0.0 + return 0.0, 0.0 + # from odoo import fields # from datetime import datetime, timedelta # import logging diff --git a/l10n_ca_hr_payroll/models/federal/ca_ei.py b/l10n_ca_hr_payroll/models/federal/ca_ei.py index f8616a60..4eee4e3e 100644 --- a/l10n_ca_hr_payroll/models/federal/ca_ei.py +++ b/l10n_ca_hr_payroll/models/federal/ca_ei.py @@ -1,2 +1,11 @@ # Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +def ca_ei(payslip, categories, worked_days, inputs): + if payslip.contract_id.ca_payroll_config_value('is_ei_exempt'): + return 0.0, 0.0 + IE = categories.GROSS # TODO how to adjust + year = payslip.dict.get_year() + D1 = -payslip.sum_category('EE_CA_EI', str(year) + '-01-01', str(year + 1) + '-01-01') + EI = round(min(889.54 - D1, 0.0158 * IE), 2) + return -EI, 100.0 diff --git a/l10n_ca_hr_payroll/models/federal/ca_fit.py b/l10n_ca_hr_payroll/models/federal/ca_fit.py index 9e252213..7034c65b 100644 --- a/l10n_ca_hr_payroll/models/federal/ca_fit.py +++ b/l10n_ca_hr_payroll/models/federal/ca_fit.py @@ -24,7 +24,7 @@ def ca_fit_federal_income_tax_withholding(payslip, categories, worked_days, inpu A = _compute_annual_taxable_income(payslip, categories) # If the result is negative, T = L. if A <= 0.0 and L: - return -L, 1.0 + return -L, 100.0 elif A <= 0.0: return 0.0, 0.0 @@ -47,10 +47,10 @@ def ca_fit_federal_income_tax_withholding(payslip, categories, worked_days, inpu K2 = 0.0 if not payslip.contract_id.ca_payroll_config_value('is_cpp_exempt'): - C = categories.EE_CA_CPP + C = -categories.EE_CA_CPP K2 += 0.15 * min(P * C, 3166.45) # min because we can only have up to if not payslip.contract_id.ca_payroll_config_value('is_ei_exempt'): - EI = categories.EE_CA_EI + EI = -categories.EE_CA_EI K2 += 0.15 * min(P * EI, 889.54) K3 = 0.0 # medical CEA = 1257.0 # TODO this is an indexed parameter @@ -60,6 +60,9 @@ def ca_fit_federal_income_tax_withholding(payslip, categories, worked_days, inpu LCF = min(750.0, 0.15 * 0.0) # 0.0 => amount deducted or withheld during the year for the acquisition by the employee of approved shares of the capital stock of a prescribed labour-sponsored venture capital corporation T1 = T3 - LCF + if T1 < 0.0: + T1 = 0.0 + T = (T1 / P) + L if T > 0.0: T = round(T, 2) diff --git a/l10n_ca_hr_payroll/models/hr_payslip.py b/l10n_ca_hr_payroll/models/hr_payslip.py index a6db2ef4..f7b1eae0 100644 --- a/l10n_ca_hr_payroll/models/hr_payslip.py +++ b/l10n_ca_hr_payroll/models/hr_payslip.py @@ -3,6 +3,8 @@ from odoo import api, fields, models from .federal.ca_fit import ca_fit_federal_income_tax_withholding +from .federal.ca_cpp import ca_cpp +from .federal.ca_ei import ca_ei class HRPayslip(models.Model): @@ -25,6 +27,8 @@ class HRPayslip(models.Model): res = super()._get_base_local_dict() res.update({ 'ca_fit_federal_income_tax_withholding': ca_fit_federal_income_tax_withholding, + 'ca_cpp': ca_cpp, + 'ca_ei': ca_ei, }) return res diff --git a/l10n_ca_hr_payroll/tests/test_ca_fed_2021_1.py b/l10n_ca_hr_payroll/tests/test_ca_fed_2021_1.py index 441e2ad7..e2f0e61b 100644 --- a/l10n_ca_hr_payroll/tests/test_ca_fed_2021_1.py +++ b/l10n_ca_hr_payroll/tests/test_ca_fed_2021_1.py @@ -24,7 +24,7 @@ class TestPayslip(TestCAPayslip): contract = self._createContract(employee, wage=salary, is_cpp_exempt=True, - if_ei_exempt=True, + is_ei_exempt=True, ) self._log('2021 tax first payslip:') @@ -50,7 +50,7 @@ class TestPayslip(TestCAPayslip): contract = self._createContract(employee, wage=salary, is_cpp_exempt=True, - if_ei_exempt=True, + is_ei_exempt=True, ) payslip = self._createPayslip(employee, date_from, date_to) cats = self._getCategories(payslip) @@ -68,7 +68,7 @@ class TestPayslip(TestCAPayslip): contract = self._createContract(employee, wage=salary, is_cpp_exempt=True, - if_ei_exempt=True, + is_ei_exempt=True, schedule_pay='weekly' ) payslip = self._createPayslip(employee, date_from, date_to) @@ -77,3 +77,43 @@ class TestPayslip(TestCAPayslip): self.assertEqual(cats.get('EE_CA_CPP', 0.0), 0.0) self.assertEqual(cats.get('EE_CA_EI', 0.0), 0.0) self.assertPayrollAlmostEqual(cats['EE_CA_FIT'], -321.05) # note calculator says 321.00 + + def test_low_wage_additional(self): + salary = 1000.0 + date_from = '2021-01-01' + date_to = '2021-01-31' + test_additional = 100.0 + + employee = self._createEmployee() + contract = self._createContract(employee, + wage=salary, + is_cpp_exempt=True, + is_ei_exempt=True, + fed_td1_additional=test_additional, + ) + + payslip = self._createPayslip(employee, date_from, date_to) + cats = self._getCategories(payslip) + self.assertEqual(cats['GROSS'], 1000.0) + self.assertEqual(cats.get('EE_CA_CPP', 0.0), 0.0) + self.assertEqual(cats.get('EE_CA_EI', 0.0), 0.0) + self.assertEqual(cats['EE_CA_FIT'], -test_additional) + + def test_basic_ei(self): + salary = 7000.0 + date_from = '2021-01-01' + date_to = '2021-01-31' + + employee = self._createEmployee() + contract = self._createContract(employee, + wage=salary, + is_cpp_exempt=True, + is_ei_exempt=False + ) + + payslip = self._createPayslip(employee, date_from, date_to) + cats = self._getCategories(payslip) + self.assertEqual(cats['GROSS'], 7000.0) + self.assertEqual(cats.get('EE_CA_CPP', 0.0), 0.0) + self.assertAlmostEqual(cats['EE_CA_EI'], -110.60) + self.assertPayrollAlmostEqual(cats['EE_CA_FIT'], -1010.90)