def ajax_check_barcode(self): value = _g('value') (code, status) = Barcode.check(value) return jsonify({'code' : code, 'status' : status})
def save_new(self): try: params = {} for k in ['customer_id', 'order_time', 'source_province_id', 'source_city_id', 'destination_province_id', 'destination_city_id', 'source_company_id', 'source_address', 'source_contact', 'source_tel', 'source_mobile', 'destination_company_id', 'destination_address', 'destination_contact', 'destination_tel', 'destination_mobile', 'ref_no', 'estimate_time', 'expect_time', 'actual_time', 'remark', 'payment_id', 'pickup_type_id', 'pack_type_id', 'qty', 'qty_ratio', 'vol', 'vol_ratio', 'weight', 'weight_ratio', 'weight_ratio', 'amount', 'insurance_charge', 'sendout_charge', 'receive_charge', 'package_charge', 'other_charge', 'load_charge', 'unload_charge', 'proxy_charge', 'note_id', 'note_no', 'source_sms', 'destination_sms', ]: params[k] = _g(k) order = OrderHeader(**params) DBSession.add(order) DBSession.flush() no = _g('no') b = Barcode.getOrCreate(no, order.ref_no) order.barcode = b.img order.no = b.value b.status = 0 # mark the barcode is use DBSession.add(TransferLog( refer_id = order.id, transfer_date = dt.now().strftime(SYSTEM_DATETIME_FORMAT), type = 0, remark = LOG_CREATE_ORDER, )) item_json = _g('item_json', '') for item in json.loads(item_json): DBSession.add(ItemDetail( header = order, item_id = item['item_id'], qty = item['qty'] or None, vol = item['vol'] or None, weight = item['weight'] or None, remark = item['remark'] or None )) # handle the upload file order.attachment = multiupload() # add the contact to the master try: DBSession.query(CustomerContact).filter(and_( CustomerContact.active == 0, CustomerContact.type == "S", CustomerContact.refer_id == order.source_company_id, CustomerContact.name == order.source_contact )).one() except: # can't find the persons in source's contacts DBSession.add(CustomerContact( customer_id = order.customer_id, type = "S", refer_id = order.source_company_id, name = order.source_contact, address = order.source_address, phone = order.source_tel, mobile = order.source_mobile )) # add the contact to the master try: DBSession.query(CustomerContact).filter(and_( CustomerContact.active == 0, CustomerContact.type == "T", CustomerContact.refer_id == order.destination_company_id, CustomerContact.name == order.destination_contact )).one() except: # can't find the persons in des's contacts DBSession.add(CustomerContact( customer_id = order.customer_id, type = "T", refer_id = order.destination_company_id, name = order.destination_contact, address = order.destination_address, phone = order.destination_tel, mobile = order.destination_mobile )) DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'review', id = order.id)) except: _error(traceback.print_exc()) flash(MSG_SERVER_ERROR, MESSAGE_ERROR) DBSession.rollback() return redirect(self.default())
def hh(self): type = _g('type') barcode = _g('barcode') if type == 'search': try: b = DBSession.query(Barcode).filter(and_(Barcode.active == 0, Barcode.value == barcode)).one() if b.status == 0 : # the barcode is used in a order try: h = DBSession.query(OrderHeader).filter(OrderHeader.no == barcode).one() params = { 'no' : h.ref_no, 'source_station' : h.source_province, 'source_company' : h.source_company, 'destination_station' : h.destination_province, 'destination_company' : h.destination_company, 'status' : h.status, } except: _error(traceback.print_exc()) params = { 'no' : unicode(MSG_RECORD_NOT_EXIST), 'source_station' : '', 'source_company' : '', 'destination_station' : '', 'destination_company' : '', 'status' : '' } elif b.status == 1 : # the barcode is reserved ,could be created a new order params = { 'no' : 'BARCODE_AVAILABLE', 'source_station' : '', 'source_company' : '', 'destination_station' : '', 'destination_company' : '', 'status' : '-2' } else: # the barcode is cancel ,equal not existed params = { 'no' : unicode(MSG_RECORD_NOT_EXIST), 'source_station' : '', 'source_company' : '', 'destination_station' : '', 'destination_company' : '', 'status' : '' } except: _error(traceback.print_exc()) params = { 'no' : unicode(MSG_RECORD_NOT_EXIST), 'source_station' : '', 'source_company' : '', 'destination_station' : '', 'destination_company' : '', 'status' : '' } return self._compose_xml_result(params) elif type == 'submit': try: action_type = _g('action_type') action_type = int(action_type) # create a draft order by the handheld if action_type == -2: no = _g('barcode') ref_no = _g('orderno') b = Barcode.getOrCreate(no, ref_no, status = 0) try: DBSession.add(OrderHeader(no = no, ref_no = ref_no, status = -2)) b.status = 0 DBSession.commit() return self._compose_xml_response(0) except: DBSession.rollback() _error(traceback.print_exc()) return self._compose_xml_response(1) h = DBSession.query(OrderHeader).filter(OrderHeader.no == barcode).one() h.update_status(action_type) if action_type == IN_WAREHOUSE[0]: remark = (u'订单: %s 确认入仓。备注:' % h.ref_no) + (_g('remark') or '') elif action_type == OUT_WAREHOUSE[0]: remark = (u'订单: %s 确认出仓。备注:' % h.ref_no) + (_g('remark') or '') elif action_type == GOODS_SIGNED[0]: remark = LOG_GOODS_SIGNED + (u'签收人:%s , 签收人电话:%s , 签收时间:%s' % (_g('contact'), _g('tel') or '', _g('time'))), h.signed_time = _g('time') h.signed_remark = _g('remark') h.signed_contact = _g('contact') h.signed_tel = _g('tel') elif action_type == GOODS_PICKUP[0]: remark = LOG_GOODS_PICKUPED + (u'提货人: %s, 提货数量: %s , 备注:%s' % (_g('contact'), _g('qty'), (_g('remark') or ''))), params = { 'action_time' : _g('time'), 'contact' : _g('contact'), 'qty' : _g('qty'), 'tel' : _g('tel'), 'remark' : _g('remark'), } obj = PickupDetail(header = h, **params) DBSession.add(obj) DBSession.add(TransferLog( refer_id = h.id, transfer_date = _g('time'), type = 0, remark = remark, )) DBSession.commit() return self._compose_xml_response(0) except: return self._compose_xml_response(1) else: return self._compose_xml_response(MSG_NO_SUCH_ACTION)