def create_order(): data = request.json if data is None: abort(400, description=gettext('invalid json request')) validate_amounts_fields_in_orders(data) order = Order(**data) order.generate_order_no() order.save_and_flush() customer = Customer.find(order.customer_id) customer.status = 'ordered' Appointment.cancel_all_for_sales_customer( order.sales_id, order.customer_id, 'Order: ' + str(order.id) + ' is created') Reception.complete_all_for_sales_customer( order.sales_id, order.customer_id, 'Order: ' + str(order.id) + ' is created') return Order.find(order.id), 201, add_location_header( dict(), url_for('api.get_order', uid=order.id))
def create_calllog(customer_id): customer = Customer.find(customer_id) if customer is None: abort(400, description=gettext(u'Customer with id %(id) not found', id=customer)) data = request.json data.pop('id', None) data.pop('created_on', None) data.pop('updated_on', None) sequence_id = data.get('sequence_id', None) call_log = None if sequence_id: call_log = Calllog.find_by_sequence_id(sequence_id) if not call_log: call_log = Calllog(**data) call_log.customer_id = customer_id call_log.store_id = customer.store_id call_log.save_and_flush() return call_log
def accept_reassign_customer(sid, cid): customer = Customer.find(cid) if customer is None or customer.sales_id != sid: abort( 400, description=gettext( u'customer with id %(id)s is not found or not belongs to sales %(sid)s', id=cid, sid=sid)) customer.reassigned = 0 return customer
def assign_customer(cid): customer = Customer.find(cid) if customer is None: abort(400, description=gettext(u'customer with id %(id)s is not found', id=cid)) new_sales_id = request.json.get('sales_id') if new_sales_id is None: abort(400, description=gettext(u'new sales id is empty')) customer.reassign(new_sales_id) return customer
def populate_customer_from_request(data, store_id, user_id): from application.models.customer import Customer customer_id = extract_customer_id(data) customer_data = data.get('customer') customer = None if not customer_id and not customer_data: abort(400, description=gettext( 'either customer_id or customer has to be provided')) elif customer_id: customer = Customer.find(customer_id) if not customer: abort(400, description=gettext('customer with id %(id)s is not found', id=data['customer_id'])) elif unicode(customer.sales_id) != unicode(user_id) and data.get( 'force', None) != 'force': raise NoPermissionOnCustomerException( customer, gettext( u'the customer %(name)s you are operating does not belong to you. Please contact your sales manager', name=customer.name)) else: if customer_data.get('mobile', None): customer = Customer.find_by_mobile(store_id, customer_data['mobile']) customer = handle_no_rx_customer(customer) if customer and unicode( customer.sales_id) != unicode(user_id) and data.get( 'force', None) != 'force': raise NoPermissionOnCustomerException( customer, gettext( u'the customer %(name)s you are operating does not belong to you. Please contact your sales manager', name=customer.name)) if not customer: customer = Customer(**customer_data) customer.store_id = store_id customer.sales_id = user_id data['customer'] = customer return data