Esempio n. 1
0
def get_reseller_profile_data(users, uid):
    ids = users.values_list('pk', flat=True)
    now = JalaliDatetime.today().replace(day=1).to_datetime()
    invoices = Invoice.objects.filter(user__in=ids, is_paid=True, pay_time__gte=now.date())
    service_invoices = Invoice.objects.filter(user__in=ids, is_paid=True, pay_time__gte=now.date(),
                                              service__service_type=1)
    package_invoices = Invoice.objects.filter(user__in=ids, is_paid=True, pay_time__gte=now.date(),
                                              service__service_type=2)
    total_services = service_invoices.aggregate(service_price=Sum('price')).get('service_price')
    if total_services is None:
        total_services = 0
    total_packages = package_invoices.aggregate(package_price=Sum('price')).get('package_price')
    if total_packages is None:
        total_packages = 0
    total_prices = invoices.aggregate(total_price=Sum('price')).get('total_price')
    if not total_prices:
        total_prices = 0
    total_invoices = invoices.count()
    total_users = users.count()
    total_invoice_users = invoices.values('user').distinct().count()
    user_profile = ResellerProfile.objects.get(user=uid)
    profit_options = user_profile.fk_reseller_profit_option_reseller
    package_profit = profit_options.package_profit
    service_profit = profit_options.service_profit
    max_negative_credit = profit_options.max_neg_credit
    total_package_price = (total_packages * package_profit) / 100
    total_service_price = (total_services * service_profit) / 100
    current_deposit = user_profile.profit_price
    return {'total_invoice': total_invoices,
            'total_users': total_users,
            'total_price': total_prices,
            'total_service_price': total_service_price,
            'total_package_price': total_package_price,
            'package_profit': package_profit,
            'service_profit': service_profit,
            'max_neg_credit': max_negative_credit,
            'invoice_users': total_invoice_users,
            'reseller_deposit': int(current_deposit)}
Esempio n. 2
0
 def test_today(self):
     dt = datetime.now().date()
     jdt = JalaliDatetime.today().date()
     self.assertEqual(jdt, JalaliDate.from_date(dt))
Esempio n. 3
0
 def test_today(self):
     dt = datetime.now().date()
     jdt = JalaliDatetime.today().date()
     self.assertEqual(jdt, JalaliDate(dt))