Add optional default product fields on tenant creation

When creating a new tenant, users can now choose to initialize with default product fields (Product Name, Item ID, Sale Price, and Image). The option is presented via a checkbox in the tenant creation modal and is enabled by default.
This commit is contained in:
2025-10-20 21:13:05 -04:00
parent 25e3848710
commit a727796ed2
3 changed files with 80 additions and 2 deletions

View File

@@ -82,3 +82,56 @@ class ARFieldModel:
cursor.execute('DELETE FROM custom_ar_fields WHERE id = ? AND tenant_id = ?',
(field_id, tenant_id))
conn.commit()
@staticmethod
def create_default_fields(tenant_id: str):
"""Create default product fields for a new tenant"""
tenant_id = tenant_id.lower()
default_fields = [
{
'fieldName': '_name',
'label': 'Product Name',
'fieldType': 'TEXT',
'editable': 'true',
'displayOrder': 0
},
{
'fieldName': '_id',
'label': 'Item ID',
'fieldType': 'TEXT',
'editable': 'false',
'displayOrder': 1
},
{
'fieldName': '_price',
'label': 'Sale Price',
'fieldType': 'TEXT',
'editable': 'true',
'displayOrder': 2
},
{
'fieldName': '_image',
'label': 'Image',
'fieldType': 'IMAGE_URI',
'editable': 'true',
'displayOrder': 3
}
]
with get_db() as conn:
cursor = conn.cursor()
for field in default_fields:
cursor.execute('''
INSERT INTO custom_ar_fields
(tenant_id, field_name, label, field_type, editable, display_order)
VALUES (?, ?, ?, ?, ?, ?)
''', (
tenant_id,
field['fieldName'],
field['label'],
field['fieldType'],
field['editable'],
field['displayOrder']
))
conn.commit()