Commit efbf1ad7 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

payroll_l10n_fr: python3 compatibility

test was simplified not to use difflib, unittest does a good job of
explaining the differences when using splitlines on long texts, no need
to compute a diff ourselves.
parent b2c75914
from erp5.component.module.DateUtils import getNumberOfDayInMonth
import six
def getLastDateOfMonth(date):
return DateTime(date.year(), date.month(), getNumberOfDayInMonth(date))
......@@ -80,10 +81,10 @@ for remuneration_block in paysheet_data_dict['remuneration']:
continue
dsn_file.append(remuneration_block)
for bonus_category in paysheet_data_dict['other_bonus'].itervalues():
for bonus_category in six.itervalues(paysheet_data_dict['other_bonus']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.52', target=bonus_category))
for bonus_category in paysheet_data_dict['other_income'].itervalues():
for bonus_category in six.itervalues(paysheet_data_dict['other_income']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.54', target=bonus_category))
# Print DSN Record
......
from erp5.component.module.DateUtils import addToDate, getIntervalBetweenDates, getNumberOfDayInMonth
import six
portal = context.getPortalObject()
portal_categories = context.portal_categories
......@@ -43,7 +44,7 @@ if block_id in ('S21.G00.31', 'S21.G00.41', 'S21.G00.72'):
change_block = kw['change_block']
change_date = kw['change_date']
rubric_value_dict[block_id + ".001"] = change_date
for rubric, value in change_block.iteritems():
for rubric, value in six.iteritems(change_block):
rubric_value_dict[rubric] = value
# Envoi
......@@ -127,7 +128,7 @@ if block_id == 'S21.G00.06':
total_manpower = 0
for _, employee_quantity in manpower_dict.items():
total_manpower += sum(employee_quantity)
return total_manpower / len(manpower_dict.keys()) # Divide by number of months
return total_manpower // len(list(manpower_dict.keys())) # Divide by number of months.
average_manpower = ''
if context.getEffectiveDate().month() == 12 and target.getRelativeUrl() == getDSNOrganisation(context):
......
from erp5.component.module.DateUtils import getNumberOfDayInMonth
import six
portal = context.getPortalObject()
portal_categories = context.portal_categories
......@@ -30,7 +31,7 @@ if block_id in ('S21.G00.31', 'S21.G00.41', 'S21.G00.72'):
change_bloc = kw['change_bloc']
change_date = kw['change_date']
rubric_value_dict[block_id + ".001"] = change_date
for rubric, value in change_bloc.iteritems():
for rubric, value in six.iteritems(change_bloc):
rubric_value_dict[rubric] = value
# Envoi
......
......@@ -59,7 +59,7 @@ for period in leave_period_list:
continue
# Let's make a DSN Bloc for this leave period
leave_category = leave_category.pop()
if period.getDestinationValue() in leave_dict.keys():
if period.getDestinationValue() in leave_dict:
leave_dict[period.getDestination()].append(getLeaveBlocAsDict(period, leave_category))
else:
leave_dict[period.getDestination()] = [getLeaveBlocAsDict(period, leave_category),]
......
from Products.ERP5Type.Message import translateString
from erp5.component.module.DateUtils import addToDate, getNumberOfDayInMonth
import six
if context.getSourceAdministration() is None \
or context.getEffectiveDate() is None \
......@@ -227,12 +228,12 @@ for employee_data_dict, paysheet_data_dict in employee_result_list:
contract_change_block_list = []
if employee in change_block_dict:
for rubric_root, change_date_block in change_block_dict[employee].iteritems():
for rubric_root, change_date_block in six.iteritems(change_block_dict[employee]):
if rubric_root == 'S21.G00.31':
for date, change_block in change_date_block.iteritems():
for date, change_block in six.iteritems(change_date_block):
dsn_file.append(getDSNBlockDict(block_id=rubric_root, change_block=change_block, change_date=date))
elif rubric_root == 'S21.G00.41':
for date, change_block in change_date_block.iteritems():
for date, change_block in six.iteritems(change_date_block):
contract_change_block_list.append(getDSNBlockDict(block_id=rubric_root, change_block=change_block, change_date=date))
employee_data_dict['contract']['S21.G00.40.019'] = establishment_registration_code
......@@ -283,13 +284,13 @@ for employee_data_dict, paysheet_data_dict in employee_result_list:
for remuneration_block in paysheet_data_dict['remuneration']:
dsn_file.append(remuneration_block)
for bonus_category in paysheet_data_dict['other_bonus'].itervalues():
for bonus_category in six.itervalues(paysheet_data_dict['other_bonus']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.52', target=bonus_category))
for bonus_category in paysheet_data_dict['other_income'].itervalues():
for bonus_category in six.itervalues(paysheet_data_dict['other_income']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.54', target=bonus_category))
for taxable_base_category in paysheet_data_dict['taxable_base'].itervalues():
for taxable_base_category in six.itervalues(paysheet_data_dict['taxable_base']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.78', target=taxable_base_category))
if taxable_base_category['code'] == '02': # Assiette Brute plafonnee
if ('063', '') in paysheet_data_dict['individual_contribution']:
......@@ -323,13 +324,13 @@ for employee_data_dict, paysheet_data_dict in employee_result_list:
dsn_file.append(getDSNBlockDict(block_id='S21.G00.81', target=paysheet_data_dict['individual_contribution'][('059', taxable_base_category['contract_id'])]))
del paysheet_data_dict['individual_contribution'][('059', taxable_base_category['contract_id'])]
for taxable_base_component_category in paysheet_data_dict['taxable_base_component'].itervalues():
for taxable_base_component_category in six.itervalues(paysheet_data_dict['taxable_base_component']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.79', target=taxable_base_component_category))
if ('03', '') in taxable_base_component_category:
dsn_file.append(getDSNBlockDict(block_id='S21.G00.81', target=paysheet_data_dict['individual_contribution'][('064', '')]))
del paysheet_data_dict['individual_contribution'][('064', '')]
for individual_contribution_category in paysheet_data_dict['individual_contribution'].itervalues():
for individual_contribution_category in six.itervalues(paysheet_data_dict['individual_contribution']):
dsn_file.append(getDSNBlockDict(block_id='S21.G00.81', target=individual_contribution_category))
dsn_file.append(employee_data_dict['seniority'])
......
......@@ -3,12 +3,12 @@ import unicodedata
data = unicodedata.normalize('NFKD', context.getTextContent().decode('utf-8')).encode('iso-8859-1', 'ignore')
# Update sending mode "on the fly"
dsn_line_list = data.split('\n')
dsn_line_list = data.split(b'\n')
for line_number, dsn_line in enumerate(dsn_line_list):
if dsn_line.split(',', 1)[0] == 'S10.G00.00.005':
dsn_line_list[line_number] = 'S10.G00.00.005,\'%s\'' % sending_mode
if dsn_line.split(b',', 1)[0] == b'S10.G00.00.005':
dsn_line_list[line_number] = b'S10.G00.00.005,\'%s\'' % sending_mode.encode()
data = '\n'.join(dsn_line_list)
data = b'\n'.join(dsn_line_list)
filename = context.getTitle()
......
import six
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery, SimpleQuery
kw["report_data"] = context.PaySheetTransaction_getPayslipData()
......@@ -59,7 +60,7 @@ if batch:
rep_content = context.PaySheetTransaction_generatePayslipReportContent(**kw)
if isinstance(rep_content, unicode):
if six.PY2 and isinstance(rep_content, six.text_type):
rep_content = rep_content.encode("utf8")
return rep_content,"",""
from DateTime import DateTime
import six
line_dict_list = context.PaySheetTransaction_getLineListAsDict()
non_subject_amount = 'base_amount/payroll/report_section/l10n/fr/amount_non_subject_to_contribution'
......@@ -59,7 +60,7 @@ def groupSameReportSectionLine(line_to_group_list):
tmp_base_dict[base]['employee_price'] = tmp_base_dict[base]['employee_price'] + (line_dict['employee_price'] or 0)
tmp_base_dict[base]['employee_total_price'] = tmp_base_dict[base]['employee_total_price'] + (line_dict['employee_total_price'] or 0)
# Check if can group by same rate
for _, value in tmp_base_dict.iteritems():
for value in six.itervalues(tmp_base_dict):
new_key = (value['employer_price'], value['employee_price'])
if new_key not in tmp2_base_dict:
tmp2_base_dict[new_key] = value
......
......@@ -24,13 +24,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import difflib
import os
import time
import six
from DateTime import DateTime
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class TestDSNSocialDeclarationReport(ERP5TypeTestCase):
"""
Test Suite for the generation of the French Social Declaration Report,
......@@ -60,8 +59,26 @@ class TestDSNSocialDeclarationReport(ERP5TypeTestCase):
"""
test_dsn = self.dsn_module['test_model']
test_dsn.DSNMonthlyReport_makeReport()
reference_DSN = getattr(self.portal.portal_skins.erp5_payroll_l10n_fr_test, "test_model.dsn").data
diff_list = []
for unit_diff in difflib.unified_diff(reference_DSN.split('\n'), test_dsn.getTextContent().split('\n')):
diff_list.append(unit_diff)
self.assertEqual(reference_DSN, test_dsn.getTextContent(), msg='\n'.join(diff_list))
reference_DSN = bytes(
getattr(self.portal.portal_skins.erp5_payroll_l10n_fr_test, "test_model.dsn").data
)
if six.PY3:
reference_DSN = reference_DSN.decode('utf-8')
self.maxDiff = None
self.assertEqual(
test_dsn.getTextContent().splitlines(),
reference_DSN.splitlines(),
)
# the export is latin1 encoded by spec, but we remove accents
ret = self.publish(
'%s/DSNMonthlyReport_printAsFile' % test_dsn.getPath(),
user='ERP5TypeTestCase')
self.assertEqual(ret.getHeader('Content-Type'), 'text/plain; charset=iso-8859-1')
self.assertIn('Clemenceau', ret.getBody().decode('iso-8859-1'))
# when exporting, we can choose another mode, there's a field in the report dialog
ret = self.publish(
'%s/DSNMonthlyReport_printAsFile?sending_mode=02' % test_dsn.getPath(),
user='ERP5TypeTestCase')
self.assertIn("S10.G00.00.005,'02'", ret.getBody().decode('iso-8859-1'))
......@@ -32,6 +32,7 @@ import cStringIO
import math
import os.path
from Products.Localizer.itools.i18n.accept import AcceptLanguage
import six
class TestSimplifiedPayslipReport(ERP5TypeTestCase):
......@@ -107,7 +108,7 @@ class TestSimplifiedPayslipReport(ERP5TypeTestCase):
"total_contribution_relief": 468.88
}
payslip_content = test_pay_sheet_transaction.PaySheetTransaction_getPayslipData()
for key, value in expected_payslip_content.iteritems():
for key, value in six.iteritems(expected_payslip_content):
self.assertAlmostEqual(value, payslip_content[key])
expected_non_contribution_dict_list= [
......@@ -124,7 +125,7 @@ class TestSimplifiedPayslipReport(ERP5TypeTestCase):
for index in range(len(expected_non_contribution_dict_list)):
expected_value_dict = expected_non_contribution_dict_list[index]
value_dict = non_contribution_dict_list[index]
for key, value in expected_value_dict.iteritems():
for key, value in six.iteritems(expected_value_dict):
self.assertEqual(value_dict[key], value)
expected_contribution_dict_list = [
......@@ -163,7 +164,7 @@ class TestSimplifiedPayslipReport(ERP5TypeTestCase):
for index in range(len(expected_contribution_dict_list)):
expected_value_dict = expected_contribution_dict_list[index]
value_dict = contribution_dict_list[index]
for key, value in expected_value_dict.iteritems():
for key, value in six.iteritems(expected_value_dict):
self.assertAlmostEqual(value_dict[key], value)
test_pay_sheet_transaction.setStartDate(DateTime("2020/01/01"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment