ciclos

ref: master

core/blueprints/reports.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Blueprint, request, render_template
from core.config import title

from functools import reduce

import pdb

from core.types.order import Order
from core.types.order_product import OrderProduct
from core.types.product import Product
from core.types.group import Group
from core.types.cycle import Cycle
import random

reports = Blueprint("reports", __name__, url_prefix = "/reports")

@reports.route("/")
def index():
    return render_template("reports.html", title = f"Relatórios - {title}")

@reports.route("/user")
def user():
    current_cycle = Cycle.query.filter_by(status = 'published').first()
    orders = current_cycle.orders
    groups = Group.query.filter(Group.id == Product.group_id).filter(OrderProduct.product_id == Product.id).filter(Order.id == OrderProduct.order_id).filter(Order.cycle_id == current_cycle.id).all()

    total = sum(list(map(lambda order: order.total(), orders)))
    total_orders = len(orders)
    total_groups = len(groups)

    return render_template("report_by_user.html",
            total = total,
            groups = groups,
            orders = orders,
            total_orders = total_orders,
            total_groups = total_groups,
            current_cycle = current_cycle,
            random = random,
            title = f"Relatório por Consumidor - {title}"
    )

@reports.route("/group")
def group():
    return render_template("report_by_group.html", title = f"Relatório por Fornecedor - {title}")