def add_vendor(self, request: HttpRequest) -> json: data = get_request_param_json('data', request) vendor_id = int(data.get('vendor_id', '')) vendor_service = self.factory.get_service('vendor') vendor = Vendor() if vendor_id: vendor = vendor_service.get_vendor(vendor_id) vendor.name = data.get('vendor_name', '') vendor.mobile_no = data.get('vendor_mobile', '') vendor.email = data.get('vendor_email', '') vendor.property = { 'address': data.get('vendor_address', ''), 'country': data.get('vendor_country', ''), 'country_code': data.get('vendor_country_code', ''), 'zip_code': data.get('vendor_zip_code', ''), 'company_email': data.get('vendor_c_email', ''), 'company_website': data.get('vendor_c_w', ''), 'company_name': data.get('vendor_c_n', ''), } vendor_service.add_update_vendor(vendor) return JsonResponse(data, safe=False)
def vendors_save_process(request): if request.session.is_empty(): return redirect('/login/') user = User.objects.get(username=request.session.get('username')) name = request.GET['name'] owner_first_name = request.GET['owner_first_name'] owner_last_name = request.GET['owner_last_name'] address = request.GET['address'] landline = request.GET['landline'] email = request.GET['email'] mobile = request.GET['mobile'] bank = request.GET['bank'] bank_number = request.GET['bank_number'] vendor = Vendor() vendor.name = name vendor.owner_first_name = owner_first_name vendor.owner_last_name = owner_last_name vendor.address = address vendor.landline = landline vendor.email = email vendor.mobile = mobile vendor.bank = bank vendor.bank_number = bank_number try: vendor.save() user.branch.vendor.add(vendor) sweetify.sweetalert(request, icon='success', title='Added Vendor Successfully', text='{} successfully added'.format(vendor.name), persistent='Dismiss') except: sweetify.sweetalert(request, icon='error', title='Something went wrong', persistent='Dismiss') return redirect('/vendor/')