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'
|
model = str(row[40]) if row[40] else 'Unknown'
|
||||||
cls = str(row[38]) if row[38] else 'Other' # Class → category
|
cls = str(row[38]) if row[38] else 'Other' # Class → category
|
||||||
branch = str(row[51]) if row[51] else ''
|
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 ''
|
device = str(row[0]) if row[0] else ''
|
||||||
|
|
||||||
# Asset name: use location string if available, else customer + address
|
# 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',
|
'snack': 'Snack', 'drink': 'Drink', 'cold drink': 'Drink',
|
||||||
'combo': 'Combo', 'food': 'Food', 'other': 'Other',
|
'combo': 'Combo', 'food': 'Food', 'other': 'Other',
|
||||||
'unknown': 'Other',
|
'unknown': 'Other',
|
||||||
'gf bev': 'GF Bev', 'gf food': 'GF Food',
|
'gf bev': 'Bev', 'gf food': 'Food',
|
||||||
'bev': 'Bev', 'snack/bev': 'Snack/Bev',
|
'bev': 'Bev', 'snack/bev': 'Snack/bev',
|
||||||
'snack/food': 'Snack/Food',
|
'snack/food': 'Snack/food',
|
||||||
}
|
}
|
||||||
cat = category_map.get(cls.strip().lower(), cls.capitalize() if cls else 'Other')
|
cat = category_map.get(cls.strip().lower(), cls.capitalize() if cls else 'Other')
|
||||||
|
|
||||||
@@ -128,11 +141,15 @@ def main(xlsx_path):
|
|||||||
address = ?,
|
address = ?,
|
||||||
customer_id = COALESCE(?, customer_id),
|
customer_id = COALESCE(?, customer_id),
|
||||||
description = ?,
|
description = ?,
|
||||||
|
dex_report_date = ?,
|
||||||
|
deployed = ?,
|
||||||
|
pulled_date = ?,
|
||||||
updated_at = datetime('now')
|
updated_at = datetime('now')
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""", (name, serial, make, model, cat, full_address,
|
""", (name, serial, make, model, cat, full_address,
|
||||||
customer_id,
|
customer_id,
|
||||||
device + ' | Branch: ' + branch if branch else device,
|
device + ' | Branch: ' + branch if branch else device,
|
||||||
|
dex_report_date or None, deployed or None, pulled_date or None,
|
||||||
aid))
|
aid))
|
||||||
stats['updated'] += 1
|
stats['updated'] += 1
|
||||||
else:
|
else:
|
||||||
@@ -140,10 +157,13 @@ def main(xlsx_path):
|
|||||||
cursor = conn.execute("""
|
cursor = conn.execute("""
|
||||||
INSERT INTO assets
|
INSERT INTO assets
|
||||||
(machine_id, name, serial_number, make, model, category,
|
(machine_id, name, serial_number, make, model, category,
|
||||||
status, address, customer_id, is_disney, created_at, updated_at, description)
|
status, address, customer_id, is_disney,
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'), ?)
|
dex_report_date, deployed, pulled_date,
|
||||||
|
created_at, updated_at, description)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'), ?)
|
||||||
""", (machine_id, name, serial, make, model, cat,
|
""", (machine_id, name, serial, make, model, cat,
|
||||||
status, full_address, customer_id, is_disney,
|
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))
|
device + ' | Branch: ' + branch if branch else device))
|
||||||
aid = cursor.lastrowid
|
aid = cursor.lastrowid
|
||||||
existing_assets[machine_id] = aid
|
existing_assets[machine_id] = aid
|
||||||
|
|||||||
Reference in New Issue
Block a user