def mobile_get_cut(request, company_id): try: c = Company.objects.get(id=company_id) except Company.DoesNotExist: return JsonError(_("Company does not exist")) if not has_permission(request.user, c, 'tax', 'view'): return JsonError(_("You have no permission to view taxes")) taxes = Tax.objects.filter(company=c) result = {} r = [] for t in taxes: r.append(tax_to_dict(request.user, c, t)) result['taxes'] = r units = UNITS result['units'] = units categories = get_all_categories(c, json=True) result['categories'] = categories discounts = get_all_discounts(request.user, c, android=True) result['discounts'] = discounts return JsonResponse(result)
def products(request, company): c = get_object_or_404(Company, url_name=company) # needs to be at least guest to view products if not has_permission(request.user, c, 'product', 'view'): return no_permission_view(request, c, _("You have no permission to view products.")) # if there are no taxes defined, don't show anything if Tax.objects.filter(company=c).count() == 0: return error(request, c, _("There are no taxes defined. Please go to tax management and define them.")) # if there are no categories defined, throw an error if Category.objects.filter(company=c).count() == 0: return error(request, c, _("There are no categories defined, please go to category management to define them.")) # fields that need to be limited in length: lengths = { 'code': max_field_length(Product, 'code'), 'price': g.DECIMAL['currency_digits'] + 1, 'purchase_price': g.DECIMAL['currency_digits'] + 1, 'shortcut': max_field_length(Product, 'shortcut'), 'stock': g.DECIMAL['quantity_digits'], 'name': max_field_length(Product, 'name'), 'tax': g.DECIMAL['percentage_decimal_places'] + 4, # up to '100.' + 'decimal_digits' } context = { 'company': c, 'title': _("Products"), 'site_title': g.MISC['site_title'], # lists 'taxes': JsonStringify(get_all_taxes(request.user, c)), 'categories': JsonStringify(get_all_categories(c, json=True)), 'units': JsonStringify(g.UNITS), 'discounts': JsonStringify(get_all_discounts(request.user, c)), # urls for ajax calls 'add_url': reverse('pos:create_product', args=[c.url_name]), # config variables 'can_edit': has_permission(request.user, c, 'product', 'edit'), 'currency': get_company_value(request.user, c, 'pos_currency'), # images 'image_dimensions': g.IMAGE_DIMENSIONS['product'], 'image_upload_formats': g.MISC['image_upload_formats'], # what can be uploaded 'max_upload_size': round(g.MISC['max_upload_image_size']/2**20, 2), # show in megabytes 'max_upload_size_bytes': g.MISC['max_upload_image_size'], # bytes for javascript # html fields 'field_lengths': lengths, 'separator': get_company_value(request.user, c, 'pos_decimal_separator'), # numbers etc 'default_tax_id': get_default_tax(request.user, c)['id'], 'decimal_places': get_company_value(request.user, c, 'pos_decimal_places')*2, # ACHTUNG: rounding comes at the end } return render(request, 'pos/manage/products.html', context)
def mobile_JSON_categories(request, company_id): try: c = Company.objects.get(id=company_id) except Company.DoesNotExist: return JsonError(_("Company does not exist")) # permissions if not has_permission(request.user, c, 'category', 'view'): return JsonError(_("You have no permission to view categories")) data = get_all_categories(c, android=True, no_category=True) # return all categories' data in JSON format return JsonOk(extra=data, safe=False)