feat(import_machines): add dex_report_date, deployed, pulled_date extraction
- Extract from row[7] (Col 8), row[34] (Col 35), row[35] (Col 36) - Handle datetime -> ISO conversion for date columns - Include in UPDATE and INSERT statements Kanban: t_3bef3c9c
This commit is contained in:
+25
-5
@@ -73,6 +73,19 @@ def main(xlsx_path):
|
||||
model = str(row[40]) if row[40] else 'Unknown'
|
||||
cls = str(row[38]) if row[38] else 'Other' # Class → category
|
||||
branch = str(row[51]) if row[51] else ''
|
||||
|
||||
# New columns from export
|
||||
dex_report_date = row[7]
|
||||
if isinstance(dex_report_date, datetime):
|
||||
dex_report_date = dex_report_date.isoformat()
|
||||
else:
|
||||
dex_report_date = str(dex_report_date) if dex_report_date else ''
|
||||
deployed = str(row[34]) if row[34] else ''
|
||||
pulled_date = row[35]
|
||||
if isinstance(pulled_date, datetime):
|
||||
pulled_date = pulled_date.isoformat()
|
||||
else:
|
||||
pulled_date = str(pulled_date) if pulled_date else ''
|
||||
device = str(row[0]) if row[0] else ''
|
||||
|
||||
# Asset name: use location string if available, else customer + address
|
||||
@@ -89,9 +102,9 @@ def main(xlsx_path):
|
||||
'snack': 'Snack', 'drink': 'Drink', 'cold drink': 'Drink',
|
||||
'combo': 'Combo', 'food': 'Food', 'other': 'Other',
|
||||
'unknown': 'Other',
|
||||
'gf bev': 'GF Bev', 'gf food': 'GF Food',
|
||||
'bev': 'Bev', 'snack/bev': 'Snack/Bev',
|
||||
'snack/food': 'Snack/Food',
|
||||
'gf bev': 'Bev', 'gf food': 'Food',
|
||||
'bev': 'Bev', 'snack/bev': 'Snack/bev',
|
||||
'snack/food': 'Snack/food',
|
||||
}
|
||||
cat = category_map.get(cls.strip().lower(), cls.capitalize() if cls else 'Other')
|
||||
|
||||
@@ -128,11 +141,15 @@ def main(xlsx_path):
|
||||
address = ?,
|
||||
customer_id = COALESCE(?, customer_id),
|
||||
description = ?,
|
||||
dex_report_date = ?,
|
||||
deployed = ?,
|
||||
pulled_date = ?,
|
||||
updated_at = datetime('now')
|
||||
WHERE id = ?
|
||||
""", (name, serial, make, model, cat, full_address,
|
||||
customer_id,
|
||||
device + ' | Branch: ' + branch if branch else device,
|
||||
dex_report_date or None, deployed or None, pulled_date or None,
|
||||
aid))
|
||||
stats['updated'] += 1
|
||||
else:
|
||||
@@ -140,10 +157,13 @@ def main(xlsx_path):
|
||||
cursor = conn.execute("""
|
||||
INSERT INTO assets
|
||||
(machine_id, name, serial_number, make, model, category,
|
||||
status, address, customer_id, is_disney, created_at, updated_at, description)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'), ?)
|
||||
status, address, customer_id, is_disney,
|
||||
dex_report_date, deployed, pulled_date,
|
||||
created_at, updated_at, description)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'), ?)
|
||||
""", (machine_id, name, serial, make, model, cat,
|
||||
status, full_address, customer_id, is_disney,
|
||||
dex_report_date or None, deployed or None, pulled_date or None,
|
||||
device + ' | Branch: ' + branch if branch else device))
|
||||
aid = cursor.lastrowid
|
||||
existing_assets[machine_id] = aid
|
||||
|
||||
Reference in New Issue
Block a user