Untitled
unknown
python
a year ago
6.6 kB
4
Indexable
from sqlalchemy.orm import Session from . import models, schemas def get_menu_details(db: Session, menu_id: int, menu_temp_id: int, brand: str, concept_id: int): menu = db.query(models.Menu).filter( models.Menu.id == menu_id, models.Menu.menuTemplateId == menu_temp_id, models.Menu.brand == brand, models.Menu.conceptId == concept_id ).first() if not menu: return None categories = db.query(models.Category).filter(models.Category.menuId == menu_id).all() category_list = [] for category in categories: category_dict = { "id": category.id, "title_en": category.titleEn, "title_ar": category.titleAr, "sequence": category.sequenceOrder, "products": [] } category_products = db.query(models.Product).join(models.CategoryProduct).filter(models.CategoryProduct.category_id == category.id).all() for product in category_products: product_dict = { "id": product.id, "sequence": product.sequenceOrder, "title_en": product.titleEn, "title_ar": product.titleAr, "description_en": product.descriptionEn, "description_ar": product.descriptionAr, "itemType": product.itemType, "catId": category.id, "isCustomizable": product.customizable, "price": product.price, "specialPrice": product.specialPrice, "strikeOutPrice": product.strikeOutPrice, "discountPrecentage": product.discountPrecentage, "services": {service.name: service.active for service in product.services}, "limited_offer": product.limited_offer, "display_day": { day.day: [{"from": tr.startTime.strftime("%H:%M:%S"), "to": tr.endTime.strftime("%H:%M:%S")} for tr in day.time_ranges] for day in product.display_times }, "spicyOutConfig": product.spicyOutConfig, "taxClassId": product.taxClassId, "lucky_day": product.lucky_day, "lucky_date_everymonth": product.lucky_date_everymonth, "last_weak_everymonth": product.last_weak_everymonth, "lucky_type": product.lucky_type, "status": product.status, "qrcode": product.qrcode, "variants": [], "steps": [], "products": [] } if product.itemType == "standalone_group": # Add variants variants = db.query(models.Variant).filter(models.Variant.productId == product.id).all() for variant in variants: variant_dict = { "id": variant.id, "title_en": variant.titleEn, "title_ar": variant.titleAr, "selIndex": variant.selIndex, "subtitle_en": variant.subtitleEn, "subtitle_ar": variant.subtitleAr, "options": [] } options = db.query(models.VariantOption).filter(models.VariantOption.variantId == variant.id).all() for option in options: option_dict = { "id": option.id, "title_en": option.titleEn, "title_ar": option.titleAr, "isSelected": option.isSelected } variant_dict["options"].append(option_dict) product_dict["variants"].append(variant_dict) # Add sub-products as variants sub_products = db.query(models.Product).filter(models.Product.parent_product_id == product.id).all() for sub_product in sub_products: sub_product_dict = { "id": sub_product.id, "sequence": sub_product.sequenceOrder, "title_en": sub_product.titleEn, "title_ar": sub_product.titleAr, "description_en": sub_product.descriptionEn, "description_ar": sub_product.descriptionAr, "itemType": sub_product.itemType, "catId": category.id, "isCustomizable": sub_product.customizable, "price": sub_product.price, "specialPrice": sub_product.specialPrice, "strikeOutPrice": sub_product.strikeOutPrice, "discountPrecentage": sub_product.discountPrecentage, "services": {service.name: service.active for service in sub_product.services}, "limited_offer": sub_product.limited_offer, "display_day": { day.day: [{"from": tr.startTime.strftime("%H:%M:%S"), "to": tr.endTime.strftime("%H:%M:%S")} for tr in day.time_ranges] for day in sub_product.display_times }, "spicyOutConfig": sub_product.spicyOutConfig, "taxClassId": sub_product.taxClassId, "lucky_day": sub_product.lucky_day, "lucky_date_everymonth": sub_product.lucky_date_everymonth, "last_weak_everymonth": sub_product.last_weak_everymonth, "lucky_type": sub_product.lucky_type, "status": sub_product.status, "qrcode": sub_product.qrcode, "steps": [], "variants": [] } product_dict["products"].append(sub_product_dict) category_dict["products"].append(product_dict) category_list.append(category_dict) result = { "requestId": menu.id, "brand": menu.brand, "conceptId": menu.conceptId, "menuId": menu.id, "menuTempId": menu.menuTemplateId, "updatedAt": menu.lastUpdateTimestamp, "categories": category_list } return result
Editor is loading...
Leave a Comment