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 reassign(self, new_sales_id): from application.models.appointment import Appointment if not new_sales_id or self.sales_id == new_sales_id: return Appointment.cancel_all_for_sales_customer(self.sales_id, self.id, u'重新分配客户') self.reassigned = True self.sales_id = new_sales_id
def defeated(self, reason=''): self.status = 'defeated' self.intent_level = '-100' self.defeated_reason = reason # cancel all active appointments and receptions from application.models.appointment import Appointment from application.models.reception import Reception Appointment.cancel_all_for_sales_customer(self.sales_id, self.id, self.status + ': ' + reason) Reception.complete_all_for_sales_customer(self.sales_id, self.id, self.status + ': ' + reason)
def create_appointment(): data = request.json if data is None: abort(400, description=gettext('invalid json request')) # validate appointment time if data.get('appt_datetime', None) is None: abort(400, description=gettext('appointment datetime can not be empty')) appt_time = parse(data.get('appt_datetime')) now_time = datetime.now() if appt_time < now_time: abort(400, description=gettext('appointment datetime must later than now')) latest_time = now_time + timedelta(days=30) if appt_time > latest_time: abort(400, description=gettext( 'appointment datetime can not be later than 30 days')) populate_customer_from_request(data, data.get('store_id'), data.get('sales_id')) data.pop('id', None) validator = get_appt_validator(data.get('store_id')) if validator: validator.validate(data) if data.get('customer', None) and data['customer'].id: Appointment.cancel_all_for_sales_customer(data['sales_id'], data['customer'].id, "new appointment created") appt = Appointment(**data) appt.customer.enlist() appt.save_and_flush() return appt, 201, add_location_header( dict(), url_for('api.get_appointment', uid=appt.id))