notion-cascade-insert 0.0.3__tar.gz → 0.0.4__tar.gz
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.
- {notion_cascade_insert-0.0.3/notion_cascade_insert.egg-info → notion_cascade_insert-0.0.4}/PKG-INFO +1 -1
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/_modidx.py +2 -8
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/core.py +12 -41
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4/notion_cascade_insert.egg-info}/PKG-INFO +1 -1
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/settings.ini +1 -1
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/LICENSE +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/MANIFEST.in +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/README.md +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/__init__.py +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/webhook.py +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/SOURCES.txt +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/dependency_links.txt +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/entry_points.txt +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/not-zip-safe +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/requires.txt +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert.egg-info/top_level.txt +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/pyproject.toml +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/setup.cfg +0 -0
- {notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/setup.py +0 -0
{notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/_modidx.py
RENAMED
|
@@ -9,12 +9,6 @@ d = { 'settings': { 'branch': 'main',
|
|
|
9
9
|
'notion_cascade_insert/core.py'),
|
|
10
10
|
'notion_cascade_insert.core.AutoLogger.__init__': ( 'core.html#autologger.__init__',
|
|
11
11
|
'notion_cascade_insert/core.py'),
|
|
12
|
-
'notion_cascade_insert.core.AutoLogger.adjust_batch': ( 'core.html#autologger.adjust_batch',
|
|
13
|
-
'notion_cascade_insert/core.py'),
|
|
14
|
-
'notion_cascade_insert.core.AutoLogger.cancel': ( 'core.html#autologger.cancel',
|
|
15
|
-
'notion_cascade_insert/core.py'),
|
|
16
|
-
'notion_cascade_insert.core.AutoLogger.handle_update': ( 'core.html#autologger.handle_update',
|
|
17
|
-
'notion_cascade_insert/core.py'),
|
|
18
12
|
'notion_cascade_insert.core.AutoLogger.process': ( 'core.html#autologger.process',
|
|
19
13
|
'notion_cascade_insert/core.py'),
|
|
20
14
|
'notion_cascade_insert.core.Database': ('core.html#database', 'notion_cascade_insert/core.py'),
|
|
@@ -22,8 +16,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
22
16
|
'notion_cascade_insert/core.py'),
|
|
23
17
|
'notion_cascade_insert.core.Database.check_db_exists': ( 'core.html#database.check_db_exists',
|
|
24
18
|
'notion_cascade_insert/core.py'),
|
|
25
|
-
'notion_cascade_insert.core.Database.
|
|
26
|
-
|
|
19
|
+
'notion_cascade_insert.core.Database.get_data_source_schema': ( 'core.html#database.get_data_source_schema',
|
|
20
|
+
'notion_cascade_insert/core.py'),
|
|
27
21
|
'notion_cascade_insert.core.JunctionDB': ( 'core.html#junctiondb',
|
|
28
22
|
'notion_cascade_insert/core.py'),
|
|
29
23
|
'notion_cascade_insert.core.JunctionDB.__init__': ( 'core.html#junctiondb.__init__',
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
# %% auto #0
|
|
6
6
|
__all__ = ['Database', 'TriggerDB', 'JunctionDB', 'LogDB', 'AutoLogger']
|
|
7
7
|
|
|
8
|
+
# %% ../nbs/00_core.ipynb #6211d16e
|
|
9
|
+
from fastcore.basics import patch
|
|
10
|
+
|
|
8
11
|
# %% ../nbs/00_core.ipynb #68712bbc
|
|
9
12
|
class Database:
|
|
10
13
|
"""Base class for interacting with a Notion database."""
|
|
@@ -18,14 +21,14 @@ class Database:
|
|
|
18
21
|
db_info = self.notion.databases.retrieve(self.db_id)
|
|
19
22
|
self.data_source_id = db_info['data_sources'][0]['id']
|
|
20
23
|
|
|
21
|
-
def
|
|
24
|
+
def get_data_source_schema(self):
|
|
22
25
|
"""Retrieve the database schema.
|
|
23
26
|
|
|
24
27
|
Returns:
|
|
25
28
|
dict: Mapping of property names to their types
|
|
26
29
|
"""
|
|
27
|
-
|
|
28
|
-
return {name: props['type'] for name, props in
|
|
30
|
+
table = self.notion.data_sources.query(self.data_source_id)
|
|
31
|
+
return {name: props['type'] for name, props in table['results'][0]['properties'].items()}
|
|
29
32
|
|
|
30
33
|
def check_db_exists(self):
|
|
31
34
|
"Check if database exists and is accessible"
|
|
@@ -59,12 +62,16 @@ class TriggerDB(Database):
|
|
|
59
62
|
def get_page_data(self,
|
|
60
63
|
page_id # Notion page ID to retrieve (the row that trigger change)
|
|
61
64
|
):
|
|
62
|
-
"""Extract status, related item ID, and quantity from
|
|
65
|
+
"""Extract status, related item ID, and quantity from the trigged row
|
|
63
66
|
"""
|
|
64
67
|
page = self.notion.pages.retrieve(page_id)
|
|
65
68
|
status = page['properties'][self.status_prop]['select']['name'] if page['properties'][self.status_prop]['select'] else None
|
|
66
69
|
relation_id = page['properties'][self.relation_prop]['relation'][0]['id'] if page['properties'][self.relation_prop]['relation'] else None
|
|
67
|
-
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
qty = page['properties'][self.qty_prop]['number']
|
|
73
|
+
except (KeyError, TypeError):
|
|
74
|
+
qty = page['properties'][self.qty_prop]['formula']['number']
|
|
68
75
|
return status, relation_id, qty
|
|
69
76
|
|
|
70
77
|
# %% ../nbs/00_core.ipynb #82d6f2e9
|
|
@@ -158,39 +165,3 @@ class AutoLogger:
|
|
|
158
165
|
if not items: return "No items found in junction"
|
|
159
166
|
for item_id, amt in items.items(): self.log_db.create_entry(item_id, self.multiplier * qty * amt, page_id, reason)
|
|
160
167
|
return f"Logged {len(items)} items"
|
|
161
|
-
|
|
162
|
-
def cancel(self, page_id):
|
|
163
|
-
"""Reverse all logs for a trigger (restore inventory)."""
|
|
164
|
-
_, relation_id, qty = self.trigger_db.get_page_data(page_id)
|
|
165
|
-
items = self.junction_db.get_items(relation_id)
|
|
166
|
-
if not items: return "No items to reverse"
|
|
167
|
-
for item_id, amt in items.items(): self.log_db.create_entry(item_id, -self.multiplier * qty * amt, page_id, 'cancelled')
|
|
168
|
-
return f"Reversed {len(items)} items"
|
|
169
|
-
|
|
170
|
-
def adjust_batch(self,
|
|
171
|
-
page_id, # Trigger page ID being adjusted
|
|
172
|
-
old_qty, # Previous quantity value
|
|
173
|
-
new_qty # New quantity value
|
|
174
|
-
):
|
|
175
|
-
"""Log the difference when batch quantity changes."""
|
|
176
|
-
status, relation_id, _ = self.trigger_db.get_page_data(page_id)
|
|
177
|
-
if status != self.trigger_status: return f"Status is {status}, not active"
|
|
178
|
-
items = self.junction_db.get_items(relation_id)
|
|
179
|
-
if not items: return "No items found"
|
|
180
|
-
delta = new_qty - old_qty
|
|
181
|
-
for item_id, amt in items.items(): self.log_db.create_entry(item_id, self.multiplier * delta * amt, page_id, 'batch_adjusted')
|
|
182
|
-
return f"Adjusted {len(items)} items by {delta} batches"
|
|
183
|
-
|
|
184
|
-
def handle_update(self,
|
|
185
|
-
page_id, # Trigger page ID that was updated
|
|
186
|
-
old_status=None, # Previous status value
|
|
187
|
-
old_qty=None # Previous quantity value
|
|
188
|
-
):
|
|
189
|
-
"""Handle any update to trigger page - detects what changed and acts accordingly."""
|
|
190
|
-
status, _, qty = self.trigger_db.get_page_data(page_id)
|
|
191
|
-
if old_status and old_status == self.trigger_status and status != self.trigger_status: return self.cancel(page_id)
|
|
192
|
-
if status == self.trigger_status:
|
|
193
|
-
if old_status and old_status != self.trigger_status: return self.process(page_id)
|
|
194
|
-
if old_qty and old_qty != qty: return self.adjust_batch(page_id, old_qty, qty)
|
|
195
|
-
return "No action needed"
|
|
196
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/__init__.py
RENAMED
|
File without changes
|
{notion_cascade_insert-0.0.3 → notion_cascade_insert-0.0.4}/notion_cascade_insert/webhook.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|