Hi everyone!
Iβve been building a fairly advanced Draft Manager system in Kodular that helps users create and manage invoice drafts. The idea is: users can add products , set quantities and discounts, and save the whole invoice locally as a draft, then resume it later to complete and submit the final bill.
Let me break down everything Iβve implemented so far β all features, how the data is saved, updated, retrieved β and finally the problem Iβm facing:
Features of My Draft Manager System
1. What I Store Per Draft Invoice
Each draft includes:
Invoice ID
Staff Name
Customer Name
Invoice Date
Total Amount
Total Discount
Remarks
List of Products Added (stored as a list of JSON objects)
2. Product Details Stored for Each Item in the Cart
For each product in the draft, I store all of the following:
Field Description
Image URL Product image (from server or assets)
Product Name Name/title of the product
Box Quantity Quantity entered in boxes
Chain Quantity Quantity entered in chains
Box Price (User Input) Box price set by user manually (via TextBox)
Chain Price (User Input) Chain price set by user manually (via TextBox)
Box Price (From Server) Default box price fetched from Google Sheet
Chain Price (From Server) Default chain price fetched from Google Sheet
Max Discount Allowed Maximum discount value allowed for that product
All of this is packed into a JSON object per product and stored as a list under a TinyDB tag like:
CART_
So the final cart structure is a list of JSON objects, one per product.
3. Where and How I Save Drafts
When user clicks βSave Draftβ:
I store draft metadata (Invoice ID, customer, staff, discount, etc.) under one TinyDB tag, like:
DRAFT_META_
I store the product list as a JSON string (list of objects) under:
DRAFT_PRODUCTS_<invoiceID>
I also maintain a master list of all draft invoice IDs under:
DRAFT_INDEX
4. How I Load Drafts Back
When user selects a draft:
I get DRAFT_META_<invoiceID> β fill all textbox fields
I get DRAFT_PRODUCTS_<invoiceID> β decode JSON list β populate ColinTreeListView
I also calculate total, discount, etc., again based on loaded products
5. Edit, Update, and Delete Products
On edit: product is reloaded into the custom notifier with all existing fields pre-filled
On update: it replaces the product in the list at its index
On delete: I remove it from the product list and update TinyDB
6. Discount Logic
Each product has a Max Discount value.
Before saving or submitting, I check:
If applied discount for the product exceeds its max allowed discount
If total discount for invoice exceeds a fixed threshold
If invalid β I show an error and block saving
PROBLEM IβM FACING
Sometimes, when I load a saved draft:
π The product list shows up as empty!
β
The metadata (staff, customer, discount, date) is loaded correctly.
β But DRAFT_PRODUCTS_<invoiceID> returns an empty list or null β so no products are shown.
This does not happen always, only rarely and randomly.
This results in an empty ColinTreeListView when the draft is opened. Due to which the Final Cart value , total Quantity , discount are not getting loaded
Notes:
Iβm using TinyDB2 for all draft-related data.
All product list data is encoded as a JSON string (using dictionary > JSON > string).
I'm using ColinTreeListView for displaying the cart items.
I Have Shared My Blocks and If Needed any more then please do let me know
Thanks to everyone in advance
Looking forward to your ideas and suggestions.