43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
# Society Self-Service
|
|
# Copyright © 2018–2020 Yingtong Li (RunasSudo)
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
from django.utils import timezone
|
|
|
|
import csv
|
|
|
|
def new_writer(f):
|
|
writer = csv.DictWriter(f, ['*ContactName', 'EmailAddress', 'POAddressLine1', 'POAddressLine2', 'POAddressLine3', 'POAddressLine4', 'POCity', 'PORegion', 'POPostalCode', 'POCountry', '*InvoiceNumber', '*InvoiceDate', '*DueDate', 'InventoryItemCode', 'Description', '*Quantity', '*UnitAmount', '*AccountCode', '*TaxType', 'TrackingName1', 'TrackingOption1', 'TrackingName2', 'TrackingOption2', 'Currency'])
|
|
writer.writeheader()
|
|
return writer
|
|
|
|
def write_row(writer, d):
|
|
writer.writerow(d)
|
|
|
|
def write_claim(writer, claim):
|
|
for item in claim.items:
|
|
write_row(writer, {
|
|
'*ContactName': claim.payee_name,
|
|
'*InvoiceNumber': 'RE-{}'.format(claim.id),
|
|
'*InvoiceDate': timezone.now().strftime('%d/%m/%Y'),
|
|
'*DueDate': timezone.now().strftime('%d/%m/%Y'),
|
|
'Description': item['Description'],
|
|
'*Quantity': str(item['Units']),
|
|
'*UnitAmount': str(item['Unit price']),
|
|
#'*AccountCode': '850', # Suspense
|
|
'*AccountCode': 'EVT-E',
|
|
'*TaxType': 'GST Free Expenses' if item['GST-free'] else 'GST on Expenses',
|
|
})
|