def get_choices(self, request): vals_list = [] ids_list = [] logging.error("field:" + self.field) logging.error(u"parent_value:" + self.parent_value) logging.error(u"parent2_value:" + str(self.add_rel_value)) if self.field.endswith('article_fk'): articles = Article.objects.filter( group_fk=self.parent_value).filter( supplier_fk=self.add_rel_value) vals_list = [x.name for x in articles] ids_list = [x.id for x in articles] if self.field.endswith('price'): article = Article.objects.get(id=self.parent_value) vals_list = [ nvl(article.delivery_price, 0), ] ids_list = [ nvl(article.delivery_price, 0), ] if self.field.endswith('group_fk'): supplier = Supplier.objects.get(id=self.parent_value) groups = ArticleGroup.objects.filter(article__supplier_fk=supplier) vals_list = [x.name for x in groups] ids_list = [x.id for x in groups] return tuple(zip(ids_list, vals_list))
def siteorder_pay_final(request): order_id = request.GET['id'] order = Order.objects.get(id=order_id) amount = str(nvl(order.dueAmount_int(), 0) * Decimal(0.572310)) text = "Финално плащане за парти" context = RequestContext(request) paypal_dict = { "business": "*****@*****.**", "amount": amount, "item_name": text, "invoice": "order-final" + str(order.id), "custom": "final-" + str(order.id) + "-" + str(order.dueAmount_int()), "notify_url": "https://partyerp.herokuapp.com" + reverse('paypal-ipn'), "return_url": "https://partyerp.herokuapp.com/accounts/profile/", "cancel_return": "https://partyerp.herokuapp.com/pay-cancel", } # Create the instance. form = PayPalPaymentsForm(initial=paypal_dict) template_data = {} template_data['form'] = form template_data['user'] = request.user template_data['payment_data'] = [ [ 'Сума', "$ %.2f" % float(amount), ], ['Основание', text], ] return render_to_response("siteorder_paypal.html", template_data, context)
def __str__(self): return str(nvl(self.rec_date, '')) + ":" + str( nvl(self.rec_time, '') ) + ":" + str(nvl(self.rec_time_end, '')) + ":" + str( nvl(self.parent, '')) + ":" + str(nvl(self.phone, '')) + ":" + str( nvl(self.child, '')) + " :" + str( formats.number_format(nvl(self.deposit, 0), 2)) + " лв."
def get_choices(self, request): vals_list = [] ids_list = [] # logging.error("field:" + self.field) # logging.error(u"parent_value:" + self.parent_value) # logging.error(u"parent2_value:" + str(self.add_rel_value)) if self.field.endswith('price'): article = Article.objects.get(id=self.parent_value) vals_list = [ nvl(article.sale_price, 0), ] ids_list = [ nvl(article.sale_price, 0), ] # if self.field.endswith('hall_price'): # article = Article.objects.get(id=self.parent_value).filter(article__group_fk=self.parent_value) # vals_list = [nvl(article.order_price,0),] # ids_list = [nvl(article.order_price,0),] return tuple(zip(ids_list, vals_list))
def set_choices_via_ajax(self, kwargs=None, is_initial=False): for field_name in self.chained_fields_names + self.chained_model_fields_names: field = self.fields[field_name] try: c = TestClient() try: if self.user: c.login_user(self.user) except AttributeError: pass additional_related_field = None additional_related_value = None if kwargs is not None: # initial data do not have any prefix if self.prefix in EMPTY_VALUES or is_initial: parent_value = kwargs.get(field.parent_field, None) field_value = kwargs.get(field_name, None) if hasattr(field, 'additional_related_field'): additional_related_field = field.additional_related_field if additional_related_field and '__' in additional_related_field: # handle reference from inline field additional_related_value = kwargs.get('%s' % (field.additional_related_field.split('__')[-1]), None) else: # handle normal reference additional_related_value = kwargs.get(field.additional_related_field, None) else: field_value = kwargs.get('%s-%s' % (self.prefix, field_name), None) if field.inline_fk_to_master: # handle reference from inline field parent_value = kwargs.get('%s' % field.parent_field, None) else: # handle normal inlined (or prefixed) reference parent_value = kwargs.get('%s-%s' % (self.prefix, field.parent_field), None) if hasattr(field, 'additional_related_field') and field.additional_related_field: additional_related_field = field.additional_related_field # a rather clumsy way to support master field lookup if additional_related_field and '__' in additional_related_field: # handle reference from inline field additional_related_value = kwargs.get('%s' % (field.additional_related_field.split('__')[-1]), None) else: # handle normal inlined (or prefixed) reference additional_related_value = kwargs.get('%s-%s' % (self.prefix, field.additional_related_field), None) else: field_value = getattr(self.instance, '%s' % field_name, None) if field.inline_fk_to_master: # handle reference from inline field parent_value = getattr(self.instance, '%s' % field.inline_fk_to_master, None) parent_value = getattr(parent_value, '%s' % field.parent_field, None) else: # handle normal/inlined reference parent_value = getattr(self.instance, '%s' % field.parent_field, None) if hasattr(field, 'additional_related_field') and field.additional_related_field: additional_related_field = field.additional_related_field # lookup "deep" references of models, split with underscores, following foreign keys obj = self.instance pref_li = additional_related_field.split('__') for x in pref_li: if obj: obj = getattr(obj, '%s' % x, None) additional_related_value = obj field.choices = [('', field.empty_label)] # check that parent_value is valid if parent_value: parent_value = getattr(parent_value, 'pk', parent_value) additional_related_value = getattr(additional_related_value, 'pk', additional_related_value) url = field.ajax_url params = { 'field': field_name, 'parent_value': parent_value, 'field_value': field_value, 'add_rel_field': nvl(additional_related_field,''), 'add_rel_value': nvl(additional_related_value,'') } data = c.get(url, params) if data is None: data = '' try: field.choices = field.choices + json.loads(data.content.decode('utf-8')) except ValueError: try: field.choices = field.choices + json.loads(data.content.decode('utf-8')) except ValueError: # raise raise ValueError(u'Data returned from ajax request (url=%(url)s, params=%(params)s) could not be deserialized to Python object. %(data)s' % { 'url': url, 'params': params, 'data': '' # str(data.content.decode('utf-8')) }) field.initial = field_value except ObjectDoesNotExist: field.choices = ()
def expense_amount(self): result = Cashdesk_detail_expense.objects.filter( cashdesk=self).aggregate(Sum('amount')) return nvl(result['amount__sum'], 0)
def end_amount(self): return round( nvl(self.end_coin_1, 0) * Decimal(0.01) + nvl(self.end_coin_2, 0) * Decimal(0.02) + nvl(self.end_coin_5, 0) * Decimal(0.05) + nvl(self.end_coin_10, 0) * Decimal(0.1) + nvl(self.end_coin_20, 0) * Decimal(0.2) + nvl(self.end_coin_50, 0) * Decimal(0.5) + nvl(self.end_coin_100, 0) * 1 + nvl(self.end_bank_2, 0) * 2 + nvl(self.end_bank_5, 0) * 5 + nvl(self.end_bank_10, 0) * 10 + nvl(self.end_bank_20, 0) * 20 + nvl(self.end_bank_50, 0) * 50 + nvl(self.end_bank_100, 0) * 100, 2)
def clean_amount(self): self.cleaned_data['amount'] = round(Decimal(nvl(self.cleaned_data.get('price',0),0)) * Decimal(nvl(self.cleaned_data.get('cnt',0),0)),2) return self.cleaned_data['amount']
def payedAmount_int(self): return Decimal( Decimal(nvl(self.deposit2, 0)) + Decimal(nvl(self.deposit, 0)) + Decimal(nvl(self.payed_final, 0)))
def dueAmount_int(self): return Decimal( Decimal(nvl(self.priceFinal_int(), 0)) - Decimal(nvl(self.deposit2, 0)) - Decimal(nvl(self.deposit, 0)) - Decimal(nvl(self.payed_final, 0)))
def priceFinal_int(self): return Decimal( Decimal(nvl(self.priceDetail_int(), 0)) - Decimal(nvl(self.priceDetail_int(), 0)) * Decimal(nvl(self.discount, 0)) / Decimal(100))
def priceDetail_int(self): result = OrderDetail.objects.filter(order_fk=self).aggregate( agg_Result=Sum(F('cnt') * F('price'))) return Decimal(nvl(result['agg_Result'], 0))
def delivery_amount(self): result = DeliveryDetail.objects.filter(delivery_fk=self).aggregate( amount=Sum(F('price') * F('cnt'))) return nvl(result['amount'], 0)
def stock_receipt_protocol_close(self, request, obj): # check if closed if obj.closed: messages.error(request, "Този протокол вече е приключен.") return ######################################################## # check Article Store availability # if Article is missing from ArticleStore -print error and abort checked = True for stock_dev in obj.stock_delivery_detail_set.all(): if stock_dev.article_store_fk.cnt - nvl( stock_dev.article_store_fk.cnt_bl, 0) < stock_dev.cnt: messages.info( request, "Няма достатъчна наличност в склада за %s. налични:%d, блокирани:%d, не достигат: %d" % (str(stock_dev.article_store_fk.article_fk), stock_dev.article_store_fk.cnt, stock_dev.article_store_fk.cnt_bl, stock_dev.cnt - (stock_dev.article_store_fk.cnt - stock_dev.article_store_fk.cnt_bl))) checked = False # if transfer create a mirror protocol in other club if checked: ######################################################### # add/substract quantities to ArticleStore for stock_dev in obj.stock_delivery_detail_set.all(): # modify Article Store entry by sustracting quantity stock_dev.article_store_fk.cnt = stock_dev.article_store_fk.cnt - stock_dev.cnt stock_dev.article_store_fk.save() for stock_dev in obj.stock_acceptance_detail_set.all(): # modify Article Store entry by adding quantity stock_dev.article_store_fk.cnt = stock_dev.article_store_fk.cnt + stock_dev.cnt stock_dev.article_store_fk.save() if obj.type == 'EXPEDITION': ######################################################### # add record to protocols stock_doc = stock_receipt_protocol() stock_doc.transfer_fk = obj stock_doc.club_fk = obj.transfer_club_fk stock_doc.transfer_club_fk = obj.club_fk stock_doc.receipt_date = datetime.now() stock_doc.type = 'EXPDELIVERY' stock_doc.note = 'Протокол към трансфер Номер %d' % (obj.id, ) stock_doc.closed = True stock_doc.save() obj.transfer_fk = stock_doc ######################################################### # add each order article as stock delivery detail within the newly created protocol for stock_dev in obj.stock_delivery_detail_set.all(): # lookup store from the other side try: artstore = ArticleStore.objects.get( club_fk=obj.transfer_club_fk, article_fk=stock_dev.article_store_fk.article_fk) except ArticleStore.DoesNotExist: artstore = ArticleStore() artstore.user = request.user artstore.club_fk = obj.transfer_club_fk artstore.article_fk = stock_dev.article_store_fk.article_fk artstore.cnt = 0 artstore.cnt_min = 0 artstore.cnt_bl = 0 artstore.cnt += stock_dev.cnt artstore.save() ######################################################### # create a corresponding acceptance detail stock_acc = stock_acceptance_detail() stock_acc.stock_protocol_fk = stock_doc stock_acc.article_store_fk = artstore stock_acc.cnt = stock_dev.cnt stock_acc.save() messages.info( request, "Добавен е протокол за трансфер от склада. от номер:%d към номер:%d" % ( obj.id, stock_doc.id, )) obj.closed = True obj.save() else: messages.error(request, "Не е приключен е протокол за изписване от склада")