mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-20 15:02:31 +00:00
Created invoice importer
Allowed payment method to be null
This commit is contained in:
@@ -362,4 +362,4 @@ class Payment(models.Model):
|
|||||||
invoice = models.ForeignKey('Invoice')
|
invoice = models.ForeignKey('Invoice')
|
||||||
date = models.DateField()
|
date = models.DateField()
|
||||||
amount = models.DecimalField(max_digits=10, decimal_places=2, help_text='Please use ex. VAT')
|
amount = models.DecimalField(max_digits=10, decimal_places=2, help_text='Please use ex. VAT')
|
||||||
method = models.CharField(max_length=2, choices=METHODS)
|
method = models.CharField(max_length=2, choices=METHODS, null=True, blank=True)
|
||||||
40
importer.py
40
importer.py
@@ -280,6 +280,43 @@ def import_nonrigs(delete=False):
|
|||||||
print(object)
|
print(object)
|
||||||
object.save()
|
object.save()
|
||||||
|
|
||||||
|
def import_invoices(delete=False):
|
||||||
|
if delete:
|
||||||
|
try:
|
||||||
|
models.Invoice.objects.all().delete()
|
||||||
|
models.Payment.objects.all().delete()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
cursor = setup_cursor()
|
||||||
|
if cursor is None:
|
||||||
|
return
|
||||||
|
sql = """SELECT id, rig_id, invoice_date, payment_date, amount FROM invoices"""
|
||||||
|
cursor.execute(sql)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
print(row)
|
||||||
|
try:
|
||||||
|
event = models.Event.objects.get(pk=row[1])
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
invoice = models.Invoice.objects.get(event=event)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
invoice = models.Invoice(pk=row[0], event=event)
|
||||||
|
invoice.save()
|
||||||
|
invoice.invoice_date = row[2]
|
||||||
|
invoice.save()
|
||||||
|
|
||||||
|
try:
|
||||||
|
payment = models.Payment.objects.get(invoice=invoice)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
payment = models.Payment(invoice=invoice)
|
||||||
|
if row[4] >= event.sum_total:
|
||||||
|
payment.amount = event.sum_total
|
||||||
|
else:
|
||||||
|
payment.amount = row[4]
|
||||||
|
payment.date = row[3]
|
||||||
|
payment.save()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# import_users()
|
# import_users()
|
||||||
@@ -289,7 +326,8 @@ def main():
|
|||||||
# import_venues(True)
|
# import_venues(True)
|
||||||
# import_rigs(True)
|
# import_rigs(True)
|
||||||
# import_eventitem(True)
|
# import_eventitem(True)
|
||||||
import_nonrigs(True)
|
# import_nonrigs(True)
|
||||||
|
import_invoices(True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user