Skip to content

Commit c4f0d03

Browse files
authored
Merge pull request #296 from ury-erp/fix/pos-checklist
fix: remove the inner container in checklist dialog and call checklist only if configured in pos profile
2 parents e9e60ae + ab594ec commit c4f0d03

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

pos/src/components/ChecklistGateDialog.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ const ChecklistGateDialog = ({ posProfile, checklistType, onComplete }: Checklis
7373
setLoadError(null);
7474

7575
try {
76-
const { items, logName: fetchedLogName } = await getChecklist(posProfile, checklistType);
76+
const { items, logName: fetchedLogName, logStatus } = await getChecklist(posProfile, checklistType);
77+
78+
if (items.length === 0 || logStatus === 'Complete') {
79+
onComplete();
80+
return;
81+
}
82+
7783
setRows(toRowState(items));
7884
setLogName(fetchedLogName);
7985
} catch (error) {
@@ -82,7 +88,7 @@ const ChecklistGateDialog = ({ posProfile, checklistType, onComplete }: Checklis
8288
} finally {
8389
setIsLoading(false);
8490
}
85-
}, [posProfile, checklistType]);
91+
}, [posProfile, checklistType, onComplete]);
8692

8793
useEffect(() => {
8894
loadChecklist();
@@ -149,7 +155,7 @@ const ChecklistGateDialog = ({ posProfile, checklistType, onComplete }: Checklis
149155
<>
150156
<div className="flex-1 overflow-y-auto space-y-4 mb-6 pr-1">
151157
{rows.map((row, index) => (
152-
<div key={`${row.item_label}-${index}`} className="border border-gray-200 rounded-lg p-3">
158+
<div key={`${row.item_label}-${index}`}>
153159
<label className="flex items-start gap-3 cursor-pointer">
154160
<input
155161
type="checkbox"

pos/src/components/POSClosingDialog.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { usePOSStore } from '../store/pos-store';
1515
import { useRootStore } from '../store/root-store';
1616
import ClosingPaymentTable from './ClosingPaymentTable';
1717
import ChecklistGateDialog from './ChecklistGateDialog';
18+
import { getChecklist } from '../lib/checklist-api';
1819
import {
1920
getOpenPosOpeningEntries,
2021
getSubCashierPosInvoices,
@@ -413,7 +414,18 @@ const POSClosingDialog = ({ open, onOpenChange, onClosingSubmitted }: POSClosing
413414
// Close submission succeeded -- gate on the Closing checklist before
414415
// notifying the parent and dismissing the dialog.
415416
if (posProfile?.name) {
416-
setShowClosingChecklist(true);
417+
try {
418+
const { logStatus } = await getChecklist(posProfile.name, 'Closing');
419+
if (logStatus !== 'Complete') {
420+
setShowClosingChecklist(true);
421+
} else {
422+
await onClosingSubmitted?.();
423+
onOpenChange(false);
424+
}
425+
} catch (error) {
426+
console.error('Failed to check closing checklist status:', error);
427+
setShowClosingChecklist(true);
428+
}
417429
} else {
418430
await onClosingSubmitted?.();
419431
onOpenChange(false);

pos/src/i18n/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"title_closing": "Closing Checklist",
181181
"description": "Please complete the checklist below before you continue.",
182182
"loading": "Loading checklist...",
183-
"remarks_placeholder": "Remarks (optional)",
183+
"remarks_placeholder": "Remarks",
184184
"submit": "Submit Checklist",
185185
"submitting": "Submitting...",
186186
"load_failed": "Failed to load checklist",

ury/ury_pos/api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,14 @@ def _validate_checklist_branch(pos_profile):
13331333
def get_checklist(pos_profile, checklist_type):
13341334
_validate_checklist_branch(pos_profile)
13351335

1336+
has_checklist = frappe.db.exists("URY Checklist Item", {"parent": pos_profile})
1337+
if not has_checklist:
1338+
return {
1339+
"items": [],
1340+
"log_name": None,
1341+
"log_status": "Complete",
1342+
}
1343+
13361344
configured_items = frappe.get_all(
13371345
"URY Checklist Item",
13381346
fields=["item_label", "applies_to", "is_mandatory"],
@@ -1356,6 +1364,8 @@ def get_checklist(pos_profile, checklist_type):
13561364
if existing_log:
13571365
log_name = existing_log[0].name
13581366
log_status = existing_log[0].status
1367+
elif not configured_items:
1368+
log_status = "Complete"
13591369

13601370
return {
13611371
"items": configured_items,
@@ -1368,6 +1378,13 @@ def get_checklist(pos_profile, checklist_type):
13681378
def submit_checklist(pos_profile, checklist_type, items, pos_opening_entry=None):
13691379
_validate_checklist_branch(pos_profile)
13701380

1381+
has_checklist = frappe.db.exists("URY Checklist Item", {"parent": pos_profile})
1382+
if not has_checklist:
1383+
return {
1384+
"status": "Complete",
1385+
"name": None,
1386+
}
1387+
13711388
items = json.loads(items)
13721389

13731390
configured_items = frappe.get_all(
@@ -1376,6 +1393,12 @@ def submit_checklist(pos_profile, checklist_type, items, pos_opening_entry=None)
13761393
filters={"parent": pos_profile, "applies_to": ["in", [checklist_type, "Both"]]},
13771394
parent_doctype="POS Profile",
13781395
)
1396+
1397+
if not configured_items:
1398+
return {
1399+
"status": "Complete",
1400+
"name": None,
1401+
}
13791402
mandatory_by_label = {row.item_label: row.is_mandatory for row in configured_items}
13801403

13811404
existing_log = frappe.get_all(

0 commit comments

Comments
 (0)