Ejemplo n.º 1
0
 def __init__(self, request, *args, **kwargs):
     super(ModifyBillingDiscountMappingForm,
           self).__init__(request, *args, **kwargs)
     self.fields['user_name'].widget.attrs['readonly'] = True
     self.fields['plan_name'].widget.attrs['readonly'] = True
     self.fields['discount_id'].choices = [(str(d['id']), d['name'])
                                           for d in get_discounts(request)]
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(UserInvoiceDetailsView,
                        self).get_context_data(**kwargs)
        id = self.kwargs['invoice_id']

        #Commented the below line to make display in sync with admin >> billing >> invoice display
        #context['invoice'] = get_invoice(self.request, id, verbose=False)
        context['invoice'] = get_invoice(self.request, id, verbose=True)
        #context['invoice'] =  get_user_inv_details(self.request, id, verbose=True)

        plans = {}
        for plan in get_plans(self.request):
            plans[plan['id']] = plan

        #Same as Admin/Invoice Details View page
        discounts = {}
        for discount in get_discounts(self.request):
            discounts[discount['id']] = discount

        for item in context['invoice']['items']:
            #item['plan'] = plans.get(item['plan_id'])['name']
            item['bill_start_date'] = item['bill_start_date'].split(' ')[0]
            item['bill_end_date'] = item['bill_end_date'].split(' ')[0]
            disc = discounts.get(item.get('discount_id'))
            if disc:
                if disc['discount_type_code'] == 'percentage':
                    item['discount'] = str(disc.get('amt')) + '%'
                elif disc['discount_type_code'] == 'override':
                    item['discount'] = '$' + str(disc.get('amt'))
                else:
                    item['discount'] = '-'
        return context
Ejemplo n.º 3
0
 def get_data(self):
     data = get_discount_mappings(self.request)
     projects = dict([(str(p.id), p) for p in get_projects(self.request)])
     disc_types = dict([(str(dt['id']), dt) for dt in get_discount_types(self.request)])
     discounts = dict([(str(d['id']), d) for d in get_discounts(self.request)])
     plans = dict([(str(p['id']), p) for p in get_plans(self.request)])
     plan_mappings = dict([(str(pm['id']), pm) for pm in get_billing_plan_mappings(self.request)])
     for item in data:
         project = projects.get(str(item['user']))
         item['user_name'] =  project.name if project else '!ERR: ' + item['user']
         if item['map_object'] == 'user_plan':
           plan_map = plan_mappings.get(item['ref_id'])
           if plan_map:
               plan = plans.get(str(plan_map['plan_id']))
               item['plan_name'] = plan['name'] if plan else '!ERR: plan: ' + str(plan_map['id'])
           else:
               '!ERR: plan mapping: ' + item['ref_id']
         disc = discounts.get(str(item['discount_id']))
         disc_type = disc_types.get(str(item['discount_type_id']))
         item['discount_type'] = disc_type['name'] if disc_type else '!ERR: ' + str(item['discount_type_id'])
         item['discount_amt'] = str(disc['amt']) + '%' if disc else '!ERR: ' + str(item['discount_id'])
         item['apply_type'] = apply_intervals.get(item['apply_type']) or '!ERR: ' + item['apply_type']
         if item['apply_amt']:
             item['discount_amt'] = item['apply_amt']
     return data
Ejemplo n.º 4
0
 def __init__(self, request, *args, **kwargs):
     super(CreateBillingDiscountMappingForm,
           self).__init__(request, *args, **kwargs)
     self.fields['user_name'].choices = [
         (acct['user_id'], acct['user'])
         for acct in get_billing_type_mappings(request, verbose=True)
     ]
     self.fields['user_name'].choices.insert(0, (0, ''))
     self.fields['discount_id'].choices = [(str(d['id']), d['name'])
                                           for d in get_discounts(request)]
     self.fields['plan_name'].validate = lambda v: True
Ejemplo n.º 5
0
    def get_discounts_data(self):
        try:
            data = get_discounts(self.request)
            return data

        except Exception:
            self._has_more = False
            error_message = _('Unable to get discounts')
            exceptions.handle(self.request, error_message)

            return []
Ejemplo n.º 6
0
 def get_context_data(self, **kwargs):
     context = super(BillingInvoiceDetailsView,
                     self).get_context_data(**kwargs)
     id = self.kwargs['id']
     context['invoice'] = get_invoice(self.request, id, verbose=True)
     discounts = dict([(d['id'], d) for d in get_discounts(self.request)])
     for item in context['invoice']['items']:
         item['bill_start_date'] = item['bill_start_date'].split(' ')[0]
         item['bill_end_date'] = item['bill_end_date'].split(' ')[0]
         disc = discounts.get(item.get('discount_id'))
         if disc:
             if disc['discount_type_code'] == 'percentage':
                 item['discount'] = str(disc.get('amt')) + '%'
             elif disc['discount_type_code'] == 'override':
                 item['discount'] = '$' + str(disc.get('amt'))
             else:
                 item['discount'] = '-'
     return context