@rangka-os/create 0.5.0-alpha.13 → 0.5.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/base/modules/kitchen/flows/kitchen_ticket_on_sale.rk +26 -8
- package/template/base/modules/kitchen/flows/kitchen_ticket_on_update.rk +5 -1
- package/template/base/modules/kitchen/flows/kitchen_ticket_on_void.rk +9 -1
- package/template/base/modules/kitchen/models/kitchen_guard.rk +5 -0
- package/template/base/modules/kitchen/models/kitchen_ticket.rk +5 -0
- package/template/base/modules/outlet_sales/flows/moka_daily_sales.rk +39 -18
- package/template/base/modules/outlet_sales/flows/moka_line_mapped.rk +16 -1
- package/template/base/modules/outlet_sales/flows/moka_transaction_staged.rk +85 -24
- package/template/base/modules/outlet_sales/models/moka_sale_line.rk +6 -1
- package/template/base/modules/pos/models/pos_sale.rk +2 -1
- package/template/base/modules/pos/models/pos_sale_item.rk +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rangka-os/create",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.14",
|
|
4
4
|
"description": "Start a Rangka OS project: npm create @rangka-os@latest my-shop",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"homepage": "https://rangka-os.github.io/rangka-os/guide/quick-start",
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
2
|
# Runs inside a receipt's payment (pos_sale submitted), as the cashier: one ticket per active station of the outlet
|
|
3
|
-
# with the receipt's lines whose item category is routed to that station
|
|
4
|
-
# (a shop) and a receipt without kitchen lines make nothing. A
|
|
5
|
-
#
|
|
3
|
+
# with the receipt's lines whose item category (pos_sale_item.category, kept on the line) is routed to that station
|
|
4
|
+
# (kitchen_route). An outlet without stations (a shop) and a receipt without kitchen lines make nothing. A failure here
|
|
5
|
+
# rolls the payment back, so a paid receipt never misses its tickets.
|
|
6
|
+
# A receipt paid again after a void (amend) is a revision: what the voided receipt's picked-up tickets of that station
|
|
7
|
+
# already sent out is not cooked again. The served quantity of an item is spread over the revision's lines of that item
|
|
8
|
+
# in their order (line idx), so two lines of one item never both count the same served portion. The rest goes to the kitchen as Baru, and the part already served is kept as a
|
|
9
|
+
# ticket that is Diambil from the start, so a later revision knows it too.
|
|
6
10
|
name: kitchen_ticket_on_sale
|
|
7
11
|
label: {id: 'Struk dibayar: kirim tiket ke stasiun dapur'}
|
|
8
12
|
on: pos_sale.submitted
|
|
@@ -11,13 +15,15 @@ steps:
|
|
|
11
15
|
- if: stations.size() > 0
|
|
12
16
|
then:
|
|
13
17
|
- {find_all: kitchen_route, where: outlet == event.outlet, as: routes}
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
- if: event.amended_from != ''
|
|
19
|
+
then:
|
|
20
|
+
- {find_all: kitchen_ticket, where: "sale == event.amended_from && status == 'picked_up'", as: served}
|
|
21
|
+
else:
|
|
22
|
+
- {find_all: kitchen_station, where: "false", as: served}
|
|
17
23
|
- for_each: stations
|
|
18
24
|
as: st
|
|
19
25
|
do:
|
|
20
|
-
- if: "event.items.filter(l,
|
|
26
|
+
- if: "event.items.filter(l, routes.filter(r, r.station == st.name && r.category == l.category).size() > 0 && l.qty - max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())) > 0).size() > 0"
|
|
21
27
|
create: kitchen_ticket
|
|
22
28
|
set:
|
|
23
29
|
sale: event.name
|
|
@@ -26,4 +32,16 @@ steps:
|
|
|
26
32
|
date: event.date
|
|
27
33
|
buyer: event.buyer
|
|
28
34
|
revision_of: event.amended_from
|
|
29
|
-
items: "event.items.filter(l,
|
|
35
|
+
items: "event.items.filter(l, routes.filter(r, r.station == st.name && r.category == l.category).size() > 0 && l.qty - max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())) > 0).map(l, {'item': l.item, 'description': l.description, 'qty': l.qty - max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())), 'uom': l.uom, 'note': l.note})"
|
|
36
|
+
- if: "event.items.filter(l, routes.filter(r, r.station == st.name && r.category == l.category).size() > 0 && max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())) > 0).size() > 0"
|
|
37
|
+
create: kitchen_ticket
|
|
38
|
+
set:
|
|
39
|
+
sale: event.name
|
|
40
|
+
outlet: event.outlet
|
|
41
|
+
station: st.name
|
|
42
|
+
date: event.date
|
|
43
|
+
buyer: event.buyer
|
|
44
|
+
revision_of: event.amended_from
|
|
45
|
+
status: "'picked_up'"
|
|
46
|
+
picked_up_at: now()
|
|
47
|
+
items: "event.items.filter(l, routes.filter(r, r.station == st.name && r.category == l.category).size() > 0 && max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())) > 0).map(l, {'item': l.item, 'description': l.description, 'qty': max(0, min(l.qty, served.filter(t, t.station == st.name).map(t, t.served.map(x, x.item == l.item ? x.qty : 0).sum()).sum() - event.items.filter(y, y.item == l.item && y.idx < l.idx).map(y, y.qty).sum())), 'uom': l.uom, 'note': l.note})"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# A ticket's status moves one step at a time, forward or back (Baru -> Dimasak -> Siap -> Diambil; back is the work
|
|
3
3
|
# screen's "Urungkan"), and each step is stamped with its time; a step back clears the stamp of the step undone. Batal
|
|
4
4
|
# is set only by flow kitchen_ticket_on_void (writes by flows start no flow), so a person cannot void a ticket, and a
|
|
5
|
-
# void ticket does not come back. Runs inside the write, as the writer; kitchen_guard refuses the write.
|
|
5
|
+
# void ticket does not come back, nor does a picked-up ticket of a voided receipt (sale_void). Runs inside the write, as the writer; kitchen_guard refuses the write.
|
|
6
6
|
name: kitchen_ticket_on_update
|
|
7
7
|
label: {id: 'Tiket dapur diubah: satu langkah, catat waktunya'}
|
|
8
8
|
on: kitchen_ticket.updated
|
|
@@ -14,6 +14,10 @@ steps:
|
|
|
14
14
|
- if: event.status == 'void'
|
|
15
15
|
create: kitchen_guard
|
|
16
16
|
set: {reason: "'void_by_receipt'", document: event.name}
|
|
17
|
+
# a picked-up ticket of a voided receipt stays picked up: its receipt no longer exists to cook for
|
|
18
|
+
- if: event.before.status == 'picked_up' && event.sale_void
|
|
19
|
+
create: kitchen_guard
|
|
20
|
+
set: {reason: "'sale_void'", document: event.name}
|
|
17
21
|
# positions 0..3; a jump of more than one step is refused
|
|
18
22
|
- if: "event.status != 'void' && event.before.status != 'void' && ({'new': 0, 'cooking': 1, 'ready': 2, 'picked_up': 3}[event.status] - {'new': 0, 'cooking': 1, 'ready': 2, 'picked_up': 3}[event.before.status]) * ({'new': 0, 'cooking': 1, 'ready': 2, 'picked_up': 3}[event.status] - {'new': 0, 'cooking': 1, 'ready': 2, 'picked_up': 3}[event.before.status]) > 1"
|
|
19
23
|
create: kitchen_guard
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
2
|
# A voided receipt (pos_sale cancelled, same day, open shift) voids its tickets that are not picked up yet, as the
|
|
3
|
-
# cashier who voided it; the kitchen screen drops them. A ticket already picked up stays
|
|
3
|
+
# cashier who voided it; the kitchen screen drops them. A ticket already picked up stays Diambil (the food went out)
|
|
4
|
+
# and is marked sale_void, so it cannot be pulled back into the queue (flow kitchen_ticket_on_update).
|
|
4
5
|
name: kitchen_ticket_on_void
|
|
5
6
|
label: {id: 'Struk dibatalkan: tiket dapurnya batal'}
|
|
6
7
|
on: pos_sale.cancelled
|
|
@@ -13,3 +14,10 @@ steps:
|
|
|
13
14
|
set:
|
|
14
15
|
status: "'void'"
|
|
15
16
|
void_at: now()
|
|
17
|
+
- {find_all: kitchen_ticket, where: "sale == event.name && status == 'picked_up' && !sale_void", as: served}
|
|
18
|
+
- for_each: served
|
|
19
|
+
as: t
|
|
20
|
+
do:
|
|
21
|
+
- update: t
|
|
22
|
+
set:
|
|
23
|
+
sale_void: "true"
|
|
@@ -19,6 +19,7 @@ fields:
|
|
|
19
19
|
- {value: ticket_void, label: {id: Tiket sudah batal}}
|
|
20
20
|
- {value: void_by_receipt, label: {id: Batal hanya dari struk}}
|
|
21
21
|
- {value: one_step, label: {id: Satu langkah}}
|
|
22
|
+
- {value: sale_void, label: {id: Struk sudah batal}}
|
|
22
23
|
- {name: document, type: data, label: {id: Dokumen}}
|
|
23
24
|
rules:
|
|
24
25
|
- name: ticket_void
|
|
@@ -33,3 +34,7 @@ rules:
|
|
|
33
34
|
on: save
|
|
34
35
|
check: reason != 'one_step'
|
|
35
36
|
message: {id: 'Status tiket maju atau mundur satu langkah saja (Baru, Dimasak, Siap, Diambil)'}
|
|
37
|
+
- name: sale_void
|
|
38
|
+
on: save
|
|
39
|
+
check: reason != 'sale_void'
|
|
40
|
+
message: {id: 'Struk tiket ini sudah dibatalkan; tiket yang sudah diambil tidak bisa dikembalikan ke antrean'}
|
|
@@ -36,6 +36,11 @@ fields:
|
|
|
36
36
|
in_list: true
|
|
37
37
|
- {name: items, type: table, of: kitchen_ticket_item, label: {id: Menu}, read_only: true, min_rows: 1}
|
|
38
38
|
- {name: item_count, type: float, label: {id: Jumlah porsi}, compute: "items.map(l, l.qty).sum()"}
|
|
39
|
+
# the lines as a list a flow can read (a flow's find does not load table rows): a revision of the receipt does not
|
|
40
|
+
# cook again what a picked-up ticket already sent out (flow kitchen_ticket_on_sale)
|
|
41
|
+
- {name: served, type: json, label: {id: Menu (data)}, hidden: true, compute: "items.map(l, {'item': l.item, 'qty': l.qty})"}
|
|
42
|
+
# set by flow kitchen_ticket_on_void on a ticket already picked up when its receipt is voided: it stays Diambil
|
|
43
|
+
- {name: sale_void, type: check, label: {id: Struk dibatalkan}, read_only: true}
|
|
39
44
|
- name: status
|
|
40
45
|
type: select
|
|
41
46
|
label: {id: Status}
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
# (legacy_key_overlap) and rule legacy_key_reviewed holds its submit until head office has removed what is counted
|
|
10
10
|
# twice; an export imported after the API day is flagged by flow moka_legacy_key_overlap.
|
|
11
11
|
# An unmapped line waits in Baris penjualan Moka and does not hold anything back; once mapped it joins the next recap.
|
|
12
|
+
# One run is one unit of work: a refused create would roll back every outlet-day of the run, and the next run would
|
|
13
|
+
# pick the same oldest day again. So before creating, the lines whose item was deleted, whose outlet was deleted or
|
|
14
|
+
# whose outlet no longer uses Moka (Nama outlet di Moka emptied) go back to unmapped with that item or outlet emptied,
|
|
15
|
+
# head office is told, and the other lines of the day are recapped. (The kernel lets a linked record be deleted; a
|
|
16
|
+
# rangka-os card asks it to refuse.)
|
|
17
|
+
# Cost: the kernel reads a whole model for every find, so each slot reads moka_sale_line once (the oldest staged lines,
|
|
18
|
+
# the outlet-day taken from the first) and a slot runs only while the slot before found lines: a run with nothing to
|
|
19
|
+
# recap reads the table once, a run with N outlet-days N + 1 times.
|
|
12
20
|
name: moka_daily_sales
|
|
13
21
|
label: {id: Rekap harian penjualan Moka per outlet}
|
|
14
22
|
schedule: '15 * * * *'
|
|
@@ -16,42 +24,55 @@ steps:
|
|
|
16
24
|
- for_each: "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]"
|
|
17
25
|
as: slot
|
|
18
26
|
do:
|
|
27
|
+
# the oldest staged lines; the outlet-day of this slot is the first one's (lines are sorted by date, then the
|
|
28
|
+
# slot keeps those of the same outlet and day)
|
|
19
29
|
- find_all: moka_sale_line
|
|
30
|
+
if: slot == 1 || size(batch) > 0
|
|
20
31
|
where: "status == 'staged' && outlet != '' && date < today()"
|
|
21
32
|
sort: date
|
|
22
|
-
limit: 1
|
|
23
|
-
as: first
|
|
24
|
-
- find_all: moka_sale_line
|
|
25
|
-
if: size(first) > 0
|
|
26
|
-
where: "outlet == first[0].outlet && date == first[0].date && status == 'staged'"
|
|
27
|
-
sort: name
|
|
28
33
|
limit: 1000
|
|
29
|
-
as:
|
|
34
|
+
as: batch
|
|
30
35
|
- find: outlet
|
|
31
|
-
if: size(
|
|
32
|
-
where: name ==
|
|
36
|
+
if: size(batch) > 0
|
|
37
|
+
where: name == batch[0].outlet
|
|
33
38
|
as: o
|
|
39
|
+
- find_all: item
|
|
40
|
+
if: size(batch) > 0
|
|
41
|
+
where: "name in batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date).map(r, r.item)"
|
|
42
|
+
as: alive
|
|
34
43
|
- find: outlet_sales
|
|
35
|
-
if: size(
|
|
36
|
-
where: "outlet ==
|
|
44
|
+
if: size(batch) > 0
|
|
45
|
+
where: "outlet == batch[0].outlet && date == batch[0].date && source == 'moka' && docstatus != 2 && key_version != 3"
|
|
37
46
|
as: filed
|
|
38
47
|
- create: outlet_sales
|
|
39
|
-
if: size(
|
|
48
|
+
if: "size(batch) > 0 && o != null && o.moka_name != '' && size(batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date && r.item in alive.map(i, i.name))) > 0"
|
|
40
49
|
set:
|
|
41
|
-
outlet:
|
|
42
|
-
date:
|
|
50
|
+
outlet: batch[0].outlet
|
|
51
|
+
date: batch[0].date
|
|
43
52
|
source: "'moka'"
|
|
44
|
-
moka_outlet:
|
|
53
|
+
moka_outlet: o.moka_name
|
|
45
54
|
key_version: "3"
|
|
46
55
|
note: "'Dari Moka API'"
|
|
47
56
|
legacy_key_overlap: filed != null
|
|
48
|
-
lines: "
|
|
57
|
+
lines: "batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date && r.item in alive.map(i, i.name)).map(r, {'item': r.item, 'description': r.description, 'qty': r.qty, 'gross': r.gross, 'discount': r.discount, 'refund': r.refund})"
|
|
49
58
|
as: sales
|
|
50
|
-
- for_each:
|
|
51
|
-
if: size(first) > 0
|
|
59
|
+
- for_each: "size(batch) > 0 && o != null && o.moka_name != '' ? batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date && r.item in alive.map(i, i.name)) : []"
|
|
52
60
|
as: r
|
|
53
61
|
do:
|
|
54
62
|
- update: r
|
|
55
63
|
set:
|
|
56
64
|
status: "'posted'"
|
|
57
65
|
sales: sales.name
|
|
66
|
+
# lines that cannot go into a record: back to unmapped, the missing item or outlet emptied, head office told
|
|
67
|
+
- for_each: "size(batch) > 0 ? batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date && (o == null || o.moka_name == '' || !(r.item in alive.map(i, i.name)))) : []"
|
|
68
|
+
as: r
|
|
69
|
+
do:
|
|
70
|
+
- update: r
|
|
71
|
+
set:
|
|
72
|
+
status: "'unmapped'"
|
|
73
|
+
outlet: "o != null && o.moka_name != '' ? r.outlet : ''"
|
|
74
|
+
item: "r.item in alive.map(i, i.name) ? r.item : ''"
|
|
75
|
+
- notify: head_office
|
|
76
|
+
if: "size(batch) > 0 && size(batch.filter(r, r.outlet == batch[0].outlet && r.date == batch[0].date && (o == null || o.moka_name == '' || !(r.item in alive.map(i, i.name))))) > 0"
|
|
77
|
+
channel: email
|
|
78
|
+
template: {id: 'Rekap Moka {batch[0].outlet} {batch[0].date}: barang/outlet terhapus atau outlet tanpa Moka, baris kembali Belum dipetakan'}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
2
|
# Head office picked the outlet and the item of an unmapped Moka line: it becomes staged and goes into the next daily
|
|
3
|
-
# recap (flow moka_daily_sales).
|
|
3
|
+
# recap (flow moka_daily_sales). The unmapped refund lines of the same Moka checkout (same transaction and checkout,
|
|
4
|
+
# or for a line without checkout the same description) take the same outlet and item and are staged with it, so a
|
|
5
|
+
# sale and its refund go into the recap together.
|
|
4
6
|
name: moka_line_mapped
|
|
5
7
|
label: {id: Baris Moka yang sudah dipetakan siap direkap}
|
|
6
8
|
on: moka_sale_line.updated
|
|
@@ -12,3 +14,16 @@ steps:
|
|
|
12
14
|
- update: rec
|
|
13
15
|
set:
|
|
14
16
|
status: "'staged'"
|
|
17
|
+
- find_all: moka_sale_line
|
|
18
|
+
if: event.qty > 0
|
|
19
|
+
where: "name != event.name && transaction == event.transaction && qty < 0 && status == 'unmapped' && (event.checkout != '' ? checkout == event.checkout : (checkout == '' && description == 'Retur ' + event.description))"
|
|
20
|
+
as: refunds
|
|
21
|
+
- for_each: refunds
|
|
22
|
+
if: event.qty > 0
|
|
23
|
+
as: r
|
|
24
|
+
do:
|
|
25
|
+
- update: r
|
|
26
|
+
set:
|
|
27
|
+
outlet: event.outlet
|
|
28
|
+
item: event.item
|
|
29
|
+
status: "'staged'"
|
|
@@ -1,42 +1,60 @@
|
|
|
1
1
|
# yaml-language-server: $schema=https://rangka-os.github.io/rangka-os/schema/0.5/flow.json
|
|
2
|
-
# Moka API (connector moka, poll per outlet every
|
|
3
|
-
# moka_sale_line per item, plus a refund line per refunded
|
|
4
|
-
# makes the outlet's daily sales draft from the lines, and
|
|
2
|
+
# Moka API (connector moka, poll per outlet every 5 minutes of the transactions CHANGED since two days back): the first
|
|
3
|
+
# event of a transaction becomes a moka_transaction and one moka_sale_line per item, plus a refund line per refunded
|
|
4
|
+
# quantity. Nothing touches stock here: flow moka_daily_sales makes the outlet's daily sales draft from the lines, and
|
|
5
|
+
# stock moves when head office submits it (as with the export).
|
|
5
6
|
# Outlet: Moka's outlet id (outlet.moka_outlet_id), else Moka's outlet name (outlet.moka_name). Item: Moka's SKU = the
|
|
6
7
|
# item's sku, else Moka's item name = item_name. A line without outlet or item is unmapped and head office is told; it
|
|
7
8
|
# waits in Baris penjualan Moka until someone picks them (flow moka_line_mapped) and goes into the recap after that,
|
|
8
9
|
# as its own record for that day if the day was already recapped (an API line is posted exactly once).
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
10
|
+
# A later event of a known transaction (Moka changed it: a refund made after the sale was polled, or anything else) adds
|
|
11
|
+
# only refund lines for the quantity refunded since, per Moka checkout (moka_sale_line.checkout: the checkout's uuid,
|
|
12
|
+
# else its id), dated the day of the refund (refunded_date), staged for the recap of that day (or unmapped with its
|
|
13
|
+
# sale line, and mapped with it, flow moka_line_mapped); a change without a new refund adds nothing. A checkout without
|
|
14
|
+
# uuid or id is not matched by name (two lines of one item would share a refund): head office is told to book it.
|
|
15
|
+
# A refunded quantity counts at most the line's quantity. A checkout of qty <= 0 or a negative total is not staged:
|
|
16
|
+
# head office is told to check it in Moka.
|
|
17
|
+
# A transaction delivered twice records nothing: the kernel drops a repeated event and a known transaction only adds the
|
|
18
|
+
# refunded quantity not booked yet; moka_transaction.transaction_id is unique, so two runs racing on a new transaction
|
|
19
|
+
# roll the second back whole.
|
|
20
|
+
# Cost: one moka_transaction scan per event (the kernel reads a model whole for find); no moka_sale_line scan for a
|
|
21
|
+
# new transaction (unmapped lines are told about line by line), two per checkout for a refund.
|
|
22
|
+
# The day is the first 10 characters of created_at (Moka answers in the outlet's local time, +07:00); a time in UTC
|
|
23
|
+
# (ending in Z) is taken as WIB (+7 hours) first. The same for refunded_date. To confirm once API access is granted.
|
|
24
|
+
# Idempotency: the transaction and its refunded quantity, so a new refund is a new run and a repeat is not.
|
|
15
25
|
name: moka_transaction_staged
|
|
16
26
|
label: {id: Transaksi Moka masuk jadi baris penjualan}
|
|
17
27
|
on: moka.transaction_created
|
|
18
28
|
if: "'transaction_id' in event && 'created_at' in event && 'checkouts' in event && 'outlet_id' in event"
|
|
19
|
-
idempotency: string(event.transaction_id)
|
|
29
|
+
idempotency: "string(event.transaction_id) + ':' + string(event.checkouts.map(c, 'refunded_quantity' in c && c.refunded_quantity != null ? c.refunded_quantity : 0).sum())"
|
|
20
30
|
steps:
|
|
31
|
+
- find: moka_transaction
|
|
32
|
+
where: transaction_id == string(event.transaction_id)
|
|
33
|
+
as: known
|
|
34
|
+
# a new transaction
|
|
21
35
|
- find: outlet
|
|
36
|
+
if: known == null
|
|
22
37
|
where: "moka_outlet_id != '' && moka_outlet_id == string(event.outlet_id)"
|
|
23
38
|
as: by_id
|
|
24
39
|
- find: outlet
|
|
40
|
+
if: known == null
|
|
25
41
|
where: "moka_name != '' && moka_name == ('outlet_name' in event ? event.outlet_name : '')"
|
|
26
42
|
as: by_name
|
|
27
43
|
- create: moka_transaction
|
|
44
|
+
if: known == null
|
|
28
45
|
set:
|
|
29
46
|
transaction_id: string(event.transaction_id)
|
|
30
47
|
receipt_no: "'receipt_no' in event ? event.receipt_no : ''"
|
|
31
48
|
outlet: "by_id != null ? by_id.name : (by_name != null ? by_name.name : '')"
|
|
32
49
|
moka_outlet: "'outlet_name' in event ? event.outlet_name : string(event.outlet_id)"
|
|
33
50
|
sold_at: event.created_at
|
|
34
|
-
date: event.created_at
|
|
51
|
+
date: "string(event.created_at).matches('Z$') ? event.created_at + duration('7h') : event.created_at"
|
|
35
52
|
payment_type: "'payment_type' in event ? event.payment_type : ''"
|
|
36
53
|
total_collected: "'total_collected' in event ? event.total_collected : 0"
|
|
37
54
|
refunded: "'is_refunded' in event && event.is_refunded == true"
|
|
38
55
|
as: tx
|
|
39
56
|
- for_each: event.checkouts
|
|
57
|
+
if: known == null
|
|
40
58
|
as: c
|
|
41
59
|
do:
|
|
42
60
|
- find: item
|
|
@@ -45,12 +63,13 @@ steps:
|
|
|
45
63
|
- find: item
|
|
46
64
|
where: "item_name == c.item_name"
|
|
47
65
|
as: by_item_name
|
|
48
|
-
# a sale line only for a positive quantity, its discount never above its gross (outlet_sales rules
|
|
66
|
+
# a sale line only for a positive quantity and total, its discount never above its gross (outlet_sales rules
|
|
49
67
|
# qty_not_negative and discount_within_gross refuse anything else, and one refused line would stop the recap)
|
|
50
68
|
- create: moka_sale_line
|
|
51
|
-
if: c.quantity > 0
|
|
69
|
+
if: "c.quantity > 0 && c.total_price >= 0"
|
|
52
70
|
set:
|
|
53
71
|
transaction: tx.name
|
|
72
|
+
checkout: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
|
|
54
73
|
outlet: tx.outlet
|
|
55
74
|
date: tx.date
|
|
56
75
|
item: "by_sku != null ? by_sku.name : (by_item_name != null ? by_item_name.name : '')"
|
|
@@ -63,28 +82,70 @@ steps:
|
|
|
63
82
|
status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : 'staged'"
|
|
64
83
|
- create: moka_sale_line
|
|
65
84
|
# a refund line only when it returns money: a refund of a free item (100% discount) changes nothing and a line of
|
|
66
|
-
# qty < 0 without refund is refused by outlet_sales
|
|
67
|
-
if: "c.quantity > 0 && 'refunded_quantity' in c && c.refunded_quantity > 0 && round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * c.refunded_quantity / c.quantity) > 0"
|
|
85
|
+
# qty < 0 without refund is refused by outlet_sales; never more than the quantity sold
|
|
86
|
+
if: "c.quantity > 0 && c.total_price >= 0 && 'refunded_quantity' in c && c.refunded_quantity > 0 && round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * min(c.refunded_quantity, c.quantity) / c.quantity) > 0"
|
|
68
87
|
set:
|
|
69
88
|
transaction: tx.name
|
|
89
|
+
checkout: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
|
|
70
90
|
outlet: tx.outlet
|
|
71
91
|
date: tx.date
|
|
72
92
|
item: "by_sku != null ? by_sku.name : (by_item_name != null ? by_item_name.name : '')"
|
|
73
93
|
description: "'Retur ' + c.item_name + ('item_variant_name' in c && c.item_variant_name != '' ? ' ' + c.item_variant_name : '')"
|
|
74
94
|
sku: "'sku' in c ? c.sku : ''"
|
|
75
|
-
qty: -c.refunded_quantity
|
|
95
|
+
qty: -min(c.refunded_quantity, c.quantity)
|
|
76
96
|
gross: "0"
|
|
77
97
|
discount: "0"
|
|
78
|
-
refund: "round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * c.refunded_quantity / c.quantity)"
|
|
98
|
+
refund: "round((c.total_price - min('discount_amount' in c ? c.discount_amount : 0, c.total_price)) * min(c.refunded_quantity, c.quantity) / c.quantity)"
|
|
79
99
|
status: "tx.outlet == '' || (by_sku == null && by_item_name == null) ? 'unmapped' : 'staged'"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
- notify: head_office
|
|
101
|
+
if: "tx.outlet != '' && c.quantity > 0 && c.total_price >= 0 && by_sku == null && by_item_name == null"
|
|
102
|
+
channel: email
|
|
103
|
+
template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): barang "{c.item_name}" belum dikenali, petakan di Baris penjualan Moka'}
|
|
83
104
|
- notify: head_office
|
|
84
|
-
if: "event.checkouts.map(c, c.quantity > 0 ? 0 : 1).sum() > 0"
|
|
105
|
+
if: "known == null && event.checkouts.map(c, c.quantity > 0 && c.total_price >= 0 ? 0 : 1).sum() > 0"
|
|
85
106
|
channel: email
|
|
86
|
-
template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}) punya barang dengan qty 0 atau minus, tidak direkap. Cek di Moka'}
|
|
107
|
+
template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}) punya barang dengan qty 0 atau minus, atau total minus, tidak direkap. Cek di Moka'}
|
|
87
108
|
- notify: head_office
|
|
88
|
-
if:
|
|
109
|
+
if: "known == null && tx.outlet == ''"
|
|
89
110
|
channel: email
|
|
90
|
-
template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}):
|
|
111
|
+
template: {id: 'Moka {tx.receipt_no} ({tx.moka_outlet}, {tx.date}): outlet belum dikenali, petakan barisnya di Baris penjualan Moka'}
|
|
112
|
+
# a known transaction that changed in Moka: refunds made after the first poll
|
|
113
|
+
- for_each: event.checkouts
|
|
114
|
+
if: known != null
|
|
115
|
+
as: c
|
|
116
|
+
do:
|
|
117
|
+
- find: moka_sale_line
|
|
118
|
+
where: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : '')) != '' && transaction == known.name && qty > 0 && checkout == ('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : ''))"
|
|
119
|
+
as: sold
|
|
120
|
+
- notify: head_office
|
|
121
|
+
if: "('uuid' in c && c.uuid != null && string(c.uuid) != '' ? string(c.uuid) : ('id' in c && c.id != null ? string(c.id) : '')) == '' && 'refunded_quantity' in c && c.refunded_quantity != null && c.refunded_quantity > 0"
|
|
122
|
+
channel: email
|
|
123
|
+
template: {id: 'Moka {known.receipt_no} ({known.moka_outlet}): retur {c.item_name} tanpa ID baris Moka, catat manual'}
|
|
124
|
+
- find_all: moka_sale_line
|
|
125
|
+
if: sold != null
|
|
126
|
+
where: "transaction == known.name && qty < 0 && checkout == sold.checkout && description == 'Retur ' + sold.description"
|
|
127
|
+
as: returned
|
|
128
|
+
- create: moka_sale_line
|
|
129
|
+
if: "sold != null && 'refunded_quantity' in c && min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum() > 0 && round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty) > 0"
|
|
130
|
+
set:
|
|
131
|
+
transaction: known.name
|
|
132
|
+
checkout: sold.checkout
|
|
133
|
+
outlet: sold.outlet
|
|
134
|
+
date: "'refunded_date' in event && event.refunded_date != null && event.refunded_date != '' ? (string(event.refunded_date).matches('Z$') ? event.refunded_date + duration('7h') : event.refunded_date) : today()"
|
|
135
|
+
item: sold.item
|
|
136
|
+
description: "'Retur ' + sold.description"
|
|
137
|
+
sku: sold.sku
|
|
138
|
+
qty: -(min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum())
|
|
139
|
+
gross: "0"
|
|
140
|
+
discount: "0"
|
|
141
|
+
refund: "round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty)"
|
|
142
|
+
status: "sold.status == 'unmapped' || sold.outlet == '' || sold.item == '' ? 'unmapped' : 'staged'"
|
|
143
|
+
as: late
|
|
144
|
+
- notify: head_office
|
|
145
|
+
if: "sold != null && 'refunded_quantity' in c && min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum() > 0 && round((sold.gross - sold.discount) * (min(c.refunded_quantity, sold.qty) + returned.map(l, l.qty).sum()) / sold.qty) > 0"
|
|
146
|
+
channel: email
|
|
147
|
+
template: {id: 'Moka {known.receipt_no} ({known.moka_outlet}): retur susulan {sold.description} dicatat di Baris penjualan Moka'}
|
|
148
|
+
- update: known
|
|
149
|
+
if: "known != null && 'is_refunded' in event && event.is_refunded == true && !known.refunded"
|
|
150
|
+
set:
|
|
151
|
+
refunded: "true"
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
# record, not a child table, so the daily flow can read every line of an outlet and day with one find_all.
|
|
4
4
|
# status: staged (ready), unmapped (no outlet or no item matched: head office picks them here and the line becomes
|
|
5
5
|
# staged, flow moka_line_mapped; head office may still correct them while staged), posted (in outlet_sales `sales`). A refunded quantity is its own line, as in the
|
|
6
|
-
# export import: qty < 0, gross 0, refund = the refunded share of the line's net.
|
|
6
|
+
# export import: qty < 0, gross 0, refund = the refunded share of the line's net. A refund Moka reports after the first
|
|
7
|
+
# poll is a refund line of its own, dated the day of the refund (flow moka_transaction_staged).
|
|
8
|
+
# The recap sends a staged line back to unmapped (item or outlet emptied, head office told) when its item or outlet was
|
|
9
|
+
# deleted or the outlet no longer uses Moka, so one such line never stops the recap of other outlets and days.
|
|
7
10
|
name: moka_sale_line
|
|
8
11
|
label: {id: Baris penjualan Moka, en: Moka sales line}
|
|
9
12
|
icon: store
|
|
@@ -16,6 +19,8 @@ permissions:
|
|
|
16
19
|
- {role: head_office, read: true, export: true}
|
|
17
20
|
fields:
|
|
18
21
|
- {name: transaction, type: link, to: moka_transaction, label: {id: Transaksi Moka}, read_only: true, in_list: true}
|
|
22
|
+
# Moka's checkout id: the sale line and its refund lines share it, so a refund made later adds only what is new
|
|
23
|
+
- {name: checkout, type: data, label: {id: ID baris di Moka}, read_only: true}
|
|
19
24
|
- {name: outlet, type: link, to: outlet, label: {id: Outlet}, in_list: true}
|
|
20
25
|
- {name: date, type: date, label: {id: Tanggal}, read_only: true, in_list: true}
|
|
21
26
|
- {name: item, type: link, to: item, label: {id: Barang}, in_list: true}
|
|
@@ -13,8 +13,9 @@ name: pos_sale
|
|
|
13
13
|
label: {id: Transaksi kasir, en: Cashier sale}
|
|
14
14
|
icon: receipt
|
|
15
15
|
is_submittable: true
|
|
16
|
+
# No title_field: a receipt's title is its number (STRK-...), so a link to it (a kitchen ticket, a daily sales check)
|
|
17
|
+
# shows the number and never the total to a role that may not read the receipt.
|
|
16
18
|
naming: STRK-{outlet.code}-{YY}{MM}-{#####}
|
|
17
|
-
title_field: grand_total
|
|
18
19
|
on_submit: [stock.post_moves]
|
|
19
20
|
on_cancel: [stock.reverse_moves]
|
|
20
21
|
permissions:
|
|
@@ -7,6 +7,9 @@ name: pos_sale_item
|
|
|
7
7
|
is_child: true
|
|
8
8
|
fields:
|
|
9
9
|
- {name: item, type: link, to: item, label: {id: Barang atau menu}, required: true, peek: [rate, stock_uom]}
|
|
10
|
+
# the item's category when the line was saved: the kitchen routes a paid line by it (module kitchen) without reading
|
|
11
|
+
# the whole catalogue during the payment
|
|
12
|
+
- {name: category, type: link, to: item_category, label: {id: Kategori}, hidden: true, compute: item.category}
|
|
10
13
|
- {name: description, type: text, label: {id: Uraian}, default: item.item_name}
|
|
11
14
|
- name: packing
|
|
12
15
|
type: link
|