From 2863f218444ed9e1e2406361440266e83d68cd45 Mon Sep 17 00:00:00 2001 From: Konrad du Plessis Date: Sun, 22 Feb 2026 22:00:50 +0200 Subject: [PATCH] Fix receipt IntegrityError: set zero defaults before first save subtotal and total_amount have no default in the model, so the first receipt.save() sent NULL to MariaDB which rejects it. Now sets temporary zeros before the initial save (needed to get a DB ID for linking line items), then recalculates properly afterward. Co-Authored-By: Claude Opus 4.6 --- core/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/views.py b/core/views.py index fd6251a..0236a76 100644 --- a/core/views.py +++ b/core/views.py @@ -1254,6 +1254,13 @@ def create_receipt(request): # Save the receipt header (but don't commit yet — need to set user) receipt = form.save(commit=False) receipt.user = request.user + # Set temporary zero values so the first save doesn't fail. + # (subtotal and total_amount have no default in the model, + # so they'd be NULL — which MariaDB rejects.) + # We'll recalculate these properly after saving line items. + receipt.subtotal = Decimal('0.00') + receipt.vat_amount = Decimal('0.00') + receipt.total_amount = Decimal('0.00') receipt.save() # Save line items — link them to this receipt