35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
from django.shortcuts import render
|
|
from django.contrib.auth.decorators import login_required
|
|
from products.models import Product, ProductCategory
|
|
import json
|
|
|
|
|
|
@login_required
|
|
def pos_terminal(request):
|
|
"""
|
|
Tablet-friendly POS screen prototype.
|
|
Shows categories and in-stock products for quick tap-to-add.
|
|
"""
|
|
categories_qs = ProductCategory.objects.filter(is_active=True)
|
|
# Показываем все товары, не только in_stock
|
|
products_qs = Product.objects.all().prefetch_related('categories', 'photos')
|
|
|
|
categories = [{'id': c.id, 'name': c.name} for c in categories_qs]
|
|
products = [{
|
|
'id': p.id,
|
|
'name': p.name,
|
|
'price': str(p.actual_price),
|
|
'category_ids': [c.id for c in p.categories.all()],
|
|
'in_stock': p.in_stock,
|
|
'sku': p.sku or '',
|
|
'image': p.photos.first().get_thumbnail_url() if p.photos.exists() else None
|
|
} for p in products_qs]
|
|
|
|
context = {
|
|
'categories_json': json.dumps(categories),
|
|
'products_json': json.dumps(products),
|
|
'title': 'POS Terminal',
|
|
}
|
|
return render(request, 'pos/terminal.html', context)
|