def editdata(request, uuid): data = {'success': False} utils = Utils() company_id = request.user.profile.company_id user_obj = request.user user_id = user_obj.id try: roles = request.user.profile.roles except roles.DoesNotExist: roles = "ADMIN" try: res = Quotation_template.objects.get(uuid=uuid, company_id=company_id) if res: edit_id = res.id currency = get_currency_name(company_id) products = getTeamplteProduct(edit_id, 'order', company_id, user_id, roles) optionals = getTeamplteProduct(edit_id, 'optional', company_id, user_id, roles) product_tax_return_data = display_tax_calculation(products) expiration_date = datetime.strptime(str( res.expiration_date), "%Y-%m-%d").strftime("%m/%d/%Y") template = { 'id': res.id, 'name': res.name, 'terms_and_codition': res.terms_and_codition, 'expiration_date': (expiration_date), 'expiration_delay': (res.expiration_delay), 'products': products, 'optionals': optionals, 'currency': currency, 'amount_untaxed': res.amount_untaxed, 'tax_amount': utils.round_value(product_tax_return_data['total_tax']), 'multiple_tax': product_tax_return_data['multiple_tax_list'], 'total_amount': res.total_amount, 'opamount_untaxed': res.opamount_untaxed, 'optax_amount': res.optax_amount, 'optotal_amount': res.optotal_amount, } data['template'] = template data['success'] = True except Quotation_template.DoesNotExist: data['success'] = False return HttpResponse(json.dumps(data), content_type="application/json")
def updateTemplate(request): utils = Utils() data = {'success': False} company_id = request.user.profile.company_id user_obj = request.user json_data = json.loads(request.POST['fields']) if 'id' in json_data and json_data['id']: try: tmpl_obj = Quotation_template.objects.get(uuid=json_data['id']) tmpl_obj.name = json_data['name'] tmpl_obj.company_id = company_id tmpl_obj.update_by_user = user_obj if 'tax_amt' in json_data and json_data['tax_amt'] != '': tmpl_obj.tax_amount = int(json_data['tax_amt']) if 'untaxed_amt' in json_data and json_data['untaxed_amt'] != '': tmpl_obj.amount_untaxed = utils.round_value( json_data['untaxed_amt']) if 'tax_amt' in json_data and json_data['tax_amt'] != '': tmpl_obj.total_amount = utils.round_value( json_data['untaxed_amt']) + utils.round_value( json_data['tax_amt']) else: tmpl_obj.total_amount = utils.round_value( json_data['untaxed_amt']) if 'optax_amt' in json_data and json_data['optax_amt'] != '': tmpl_obj.optax_amount = utils.round_value( json_data['optax_amt']) if 'opuntaxed_amt' in json_data and json_data[ 'opuntaxed_amt'] != '': tmpl_obj.opamount_untaxed = utils.round_value( json_data['opuntaxed_amt']) if 'optax_amt' in json_data and json_data['optax_amt'] != '': tmpl_obj.optotal_amount = utils.round_value( json_data['opuntaxed_amt']) + utils.round_value( json_data['optax_amt']) else: tmpl_obj.optotal_amount = utils.round_value( json_data['opuntaxed_amt']) if 'notes' in json_data: tmpl_obj.terms_and_codition = json_data['notes'] if 'expiration_delay' in json_data and json_data[ 'expiration_delay'] != '': tmpl_obj.expiration_delay = json_data['expiration_delay'] tmpl_obj.expiration_date = datetime.now() + timedelta( days=int(json_data['expiration_delay'])) tmpl_obj.save() if tmpl_obj.id > 0: Quotation_template_record.objects.filter( quotation_template=tmpl_obj, company_id=company_id).delete() addProduct(json_data['products'], 'order', tmpl_obj, user_obj, company_id) addProduct(json_data['optional_products'], 'optional', tmpl_obj, user_obj, company_id) data['success'] = True data['uuid'] = json_data['id'] except Quotation_template.DoesNotExist: data['success'] = False return HttpResponse(json.dumps(data), content_type="application/json")
def getTeamplteProduct(id, line_type, company_id, user_id, roles): utils = Utils() pro_record_list = [] q_t_r_dict = Quotation_template_record.objects.filter( quotation_template_id=id, line_type=line_type).order_by('id') if len(q_t_r_dict) > 0: for o in q_t_r_dict: uom_name = '' product_name = 'Product Deleted' tax_id = '' tax_name = '' tax_computation = None tax_value = None json_uom = [] product_uuid = None if o.product_uom is not None: uom_name = o.product_uom.name if o.product_uom.category_id is not None: json_uom = getUOMforProduct(o.product_uom.category_id, company_id) if o.Product is not None: product_name = o.Product.internal_reference if o.Product.internal_reference is not None else '' product_name = product_name + ' ' product_name = product_name + o.Product.template_name if o.Product.template_name is not None else '' if o.Taxes is not None: tax_id = o.Taxes.id tax_name = o.Taxes.name tax_computation = o.Taxes.computation tax_value = o.Taxes.value if o.Product_id: product_uuid = str(o.Product.uuid) pro_record_list.append({ 'record_id': o.id, 'uuid': product_uuid, 'Product': o.Product_id, 'product_name': product_name, 'product_description': o.discription, 'product_qty': o.product_qty, 'product_uom': o.product_uom_id, 'product_uom_name': uom_name, 'product_tax_id': tax_id, 'product_tax_name': tax_name, 'product_tax_value': utils.round_value(tax_value), 'product_tax_computation': tax_computation, 'unit_price': utils.round_value(o.unit_price), 'tax_price': utils.round_value(o.tax_price), 'price_subtotal': utils.round_value(o.price_subtotal), 'price_total': utils.round_value(o.price_total), 'price_reduce': utils.round_value(o.price_reduce), 'discount': utils.round_value(o.discount), 'json_uom': json_uom, }) return pro_record_list