117 lines
5.0 KiB
Python
117 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import io
|
|
import csv
|
|
|
|
from odoo import http
|
|
from odoo.http import request, content_disposition
|
|
|
|
|
|
class MigrationDownloadController(http.Controller):
|
|
|
|
@http.route('/fusion_payroll/download_sample/<string:template_name>', type='http', auth='user')
|
|
def download_sample_csv(self, template_name, **kwargs):
|
|
"""Download a sample CSV template with demo data."""
|
|
templates = {
|
|
'employee': self._employee_sample(),
|
|
'payslip': self._payslip_sample(),
|
|
'ytd': self._ytd_sample(),
|
|
't4': self._t4_sample(),
|
|
}
|
|
if template_name not in templates:
|
|
return request.not_found()
|
|
|
|
headers, rows = templates[template_name]
|
|
output = io.StringIO()
|
|
writer = csv.writer(output)
|
|
writer.writerow(headers)
|
|
for row in rows:
|
|
writer.writerow(row)
|
|
|
|
csv_bytes = output.getvalue().encode('utf-8-sig')
|
|
filename = '%s_import_sample.csv' % template_name
|
|
|
|
return request.make_response(
|
|
csv_bytes,
|
|
headers=[
|
|
('Content-Type', 'text/csv; charset=utf-8'),
|
|
('Content-Disposition', content_disposition(filename)),
|
|
],
|
|
)
|
|
|
|
def _employee_sample(self):
|
|
headers = [
|
|
'First Name', 'Last Name', 'SIN', 'Street Address', 'City', 'Province',
|
|
'Postal Code', 'Hire Date', 'Pay Type', 'Hourly Rate', 'Annual Salary',
|
|
'Pay Frequency', 'Federal TD1 Amount', 'Provincial TD1 Amount',
|
|
'Additional Federal Tax', 'Vacation Rate', 'Payment Method', 'Dental Benefits Code',
|
|
]
|
|
rows = [
|
|
['Sarah', 'Johnson', '123-456-789', '123 Maple Street', 'Toronto', 'ON',
|
|
'M5V 2T6', '2023-03-15', 'Hourly', '28.50', '', 'Bi-Weekly', '16452', '12989',
|
|
'0', '4', 'Direct Deposit', '1'],
|
|
['Michael', 'Chen', '987-654-321', '456 Oak Avenue', 'Vancouver', 'BC',
|
|
'V6B 3K9', '2022-09-01', 'Salary', '', '78000', 'Bi-Weekly', '16452', '12273',
|
|
'50', '4', 'Direct Deposit', '3'],
|
|
['Emily', 'Tremblay', '456-789-123', '789 Pine Boulevard', 'Calgary', 'AB',
|
|
'T2P 1J9', '2024-01-10', 'Hourly', '35.00', '', 'Bi-Weekly', '16452', '21885',
|
|
'0', '6', 'Cheque', '1'],
|
|
]
|
|
return headers, rows
|
|
|
|
def _payslip_sample(self):
|
|
headers = [
|
|
'Employee Name', 'Pay Date', 'Period Start', 'Period End',
|
|
'Regular Pay', 'Overtime Pay', 'Vacation Pay', 'Stat Holiday Pay',
|
|
'Bonus', 'Gross Pay', 'RRSP', 'Union Dues',
|
|
'CPP', 'CPP2', 'EI', 'Federal Tax', 'Provincial Tax',
|
|
'Net Pay', 'Cheque #',
|
|
]
|
|
rows = [
|
|
['Sarah Johnson', '2026-01-16', '2026-01-01', '2026-01-15',
|
|
'2280.00', '0.00', '91.20', '0.00', '0.00', '2371.20', '0.00', '0.00',
|
|
'131.75', '0.00', '38.65', '272.15', '119.75', '1808.90', ''],
|
|
['Sarah Johnson', '2026-01-30', '2026-01-16', '2026-01-31',
|
|
'2280.00', '213.75', '99.75', '0.00', '0.00', '2593.50', '0.00', '0.00',
|
|
'144.98', '0.00', '42.27', '298.25', '131.22', '1976.78', ''],
|
|
['Michael Chen', '2026-01-16', '2026-01-01', '2026-01-15',
|
|
'3000.00', '0.00', '120.00', '0.00', '0.00', '3120.00', '100.00', '45.00',
|
|
'171.52', '0.00', '50.86', '385.60', '157.56', '2209.46', ''],
|
|
]
|
|
return headers, rows
|
|
|
|
def _ytd_sample(self):
|
|
headers = [
|
|
'Employee', 'YTD Gross', 'YTD CPP', 'YTD CPP2', 'YTD EI',
|
|
'YTD Federal Tax', 'YTD Provincial Tax', 'YTD RRSP', 'YTD Union Dues', 'YTD Net',
|
|
]
|
|
rows = [
|
|
['Sarah Johnson', '32500.00', '1831.06', '0.00', '529.75',
|
|
'3737.50', '1641.25', '0.00', '0.00', '24760.44'],
|
|
['Michael Chen', '42000.00', '2372.04', '168.00', '684.60',
|
|
'5460.00', '2118.60', '1300.00', '585.00', '29311.76'],
|
|
['Emily Tremblay', '36400.00', '2050.68', '0.00', '593.32',
|
|
'3276.00', '2912.00', '0.00', '0.00', '27567.00'],
|
|
]
|
|
return headers, rows
|
|
|
|
def _t4_sample(self):
|
|
headers = [
|
|
'Employee Name', 'SIN', 'Tax Year', 'Box 14 - Employment Income',
|
|
'Box 16 - CPP', 'Box 16A - CPP2', 'Box 18 - EI Premiums',
|
|
'Box 20 - RPP/RRSP', 'Box 22 - Income Tax', 'Box 24 - EI Insurable',
|
|
'Box 26 - CPP Pensionable', 'Box 44 - Union Dues',
|
|
]
|
|
rows = [
|
|
['Sarah Johnson', '123456789', '2025', '65000.00',
|
|
'3754.45', '0.00', '1064.20', '0.00', '10750.00', '65000.00',
|
|
'65000.00', '0.00'],
|
|
['Michael Chen', '987654321', '2025', '78000.00',
|
|
'4034.10', '268.00', '1077.48', '2400.00', '14820.00', '68900.00',
|
|
'71300.00', '1170.00'],
|
|
['Emily Tremblay', '456789123', '2025', '72800.00',
|
|
'4034.10', '60.00', '1077.48', '0.00', '12376.00', '68900.00',
|
|
'71300.00', '0.00'],
|
|
]
|
|
return headers, rows
|