Commit 2e42d1d0 authored by Jérome Perrin's avatar Jérome Perrin

Fix for invoices with date <= 1900

backport nexedi/erp5!694

/reviewed-on https://lab.nexedi.com/nexedi/erp5-capago/merge_requests/25
parents 1c1aa5ca f5db18fe
......@@ -63,13 +63,15 @@ def getSocialCapital(reg_cap):
preferred_date_order = context.getPortalObject().portal_preferences\
.getPreferredDateOrder() or 'ymd'
separator = '/'
def getOrderedDate(date):
if date is None:
return ''
pattern = separator.join(['%%%s' % s for s in list(preferred_date_order)])
pattern = pattern.replace('y', 'Y')
return date.strftime(pattern)
date_parts = {
'y': '%04d' % date.year(),
'm': '%02d' % date.month(),
'd': '%02d' % date.day(),
}
return '/'.join([date_parts[part] for part in preferred_date_order])
def getPaymentConditionText(order):
if 'custom' == order.getPaymentConditionTradeDate():
......
......@@ -73,13 +73,15 @@ def getCareerId(career_title):
preferred_date_order = context.getPortalObject().portal_preferences\
.getPreferredDateOrder() or 'ymd'
separator = '/'
def getOrderedDate(date):
if date is None:
return ''
pattern = separator.join(['%%%s' % s for s in list(preferred_date_order)])
pattern = pattern.replace('y', 'Y')
return date.strftime(pattern)
date_parts = {
'y': '%04d' % date.year(),
'm': '%02d' % date.month(),
'd': '%02d' % date.day(),
}
return '/'.join([date_parts[part] for part in preferred_date_order])
def getPaymentConditionText(order):
if order.getPaymentConditionPaymentEndOfMonth():
......
......@@ -100,13 +100,15 @@ year_to_date_total_employer_tax = paysheet.PaySheetTransaction_getYearToDateMove
preferred_date_order = portal.portal_preferences\
.getPreferredDateOrder() or 'ymd'
separator = '/'
def getOrderedDate(date):
if date is None:
return ''
pattern = separator.join(['%%%s' % s for s in list(preferred_date_order)])
pattern = pattern.replace('y', 'Y')
return date.strftime(pattern)
date_parts = {
'y': '%04d' % date.year(),
'm': '%02d' % date.month(),
'd': '%02d' % date.day(),
}
return '/'.join([date_parts[part] for part in preferred_date_order])
def getPaymentConditionText(paysheet):
date = ''
......
......@@ -1741,6 +1741,53 @@ class TestInvoice(TestInvoiceMixin):
if err_list:
self.fail(''.join(err_list))
def test_Invoice_viewAsODT_date_before_1900(self):
# Regression test for invoices with a date before 1900, which
# python-2.7's strftime does not support.
resource = self.portal.getDefaultModule(
self.resource_portal_type
).newContent(
portal_type=self.resource_portal_type,
title='Resource',)
file_data = FileUpload(__file__)
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client')
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor')
invoice = self.portal.getDefaultModule(
self.invoice_portal_type
).newContent(
portal_type=self.invoice_portal_type,
start_date=DateTime(102, 12, 31),
stop_date=DateTime(103, 12, 31),
title='Invoice',
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client)
invoice.newContent(
portal_type=self.invoice_line_portal_type,
resource_value=resource,
quantity=10,
price=3)
invoice.confirm()
self.tic()
data_dict = invoice.Invoice_getODTDataDict()
self.assertEqual('0102/12/31', data_dict['start_date'])
self.assertEqual('0103/12/31', data_dict['stop_date'])
# rendering is valid odf
odt = invoice.Invoice_viewAsODT()
from Products.ERP5OOo.tests.utils import Validator
odf_validator = Validator()
err_list = odf_validator.validate(odt)
if err_list:
self.fail(''.join(err_list))
def test_invoice_building_with_cells(self):
# if the order has cells, the invoice built from that order must have
# cells too
......
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