def import_supplier(payment1): print "insert supplier" DBSession.add_all([ Supplier(name = u'中深翔', display_name = u'中深翔', address = u'布吉丹竹头金鹏物流园A区A栋18-20号', mobile = '13600432849', contact_person = u'全总', remark = u'上海', payment = payment1), Supplier(name = u'深中联', display_name = u'深中联', address = u'布吉丹竹头金鹏物流园A栋5-6号', mobile = '13392826777,18902480211', contact_person = u'王总,丁小姐', remark = u'温州、台州、温岭、临海、黄岩', payment = payment1), Supplier(name = u'旺平达', display_name = u'旺平达', address = u'龙华明治大道华通源物流中心B2栋263-266号', mobile = '15099917300', contact_person = u'李飞章', remark = u'苏州、无锡、昆山、张家港、宜兴、常熟、太仓、吴江', payment = payment1), Supplier(name = u'顺福', display_name = u'顺福', address = u'丹竹头白泥坑宇达物流园3栋301-318号', phone = '89575677', mobile = '13316895558', contact_person = u'陈老板', remark = u'徐州、南通、淮安、盐城、连云港、启东', payment = payment1), Supplier(name = u'鑫金叶', display_name = u'鑫金叶', address = u'布吉李朗东西干道南岭大龙山物流园G栋1-3号', mobile = '13906667228', contact_person = u'金经理 ', remark = u'温州苍南', payment = payment1), Supplier(name = u'华发', display_name = u'华发', address = u'金鹏物流园B区9栋7-12号', mobile = '15999677737', contact_person = u' 陈老板', remark = u'南京、常州、扬州、泰州、镇江、靖江', payment = payment1), Supplier(name = u'京鹏', display_name = u'京鹏', address = u'华通源物流中心C4栋138-152号', mobile = '13066815788,13066815788', contact_person = u'老板娘 傅总', remark = u'杭州、上虞、湖州、德清、临安、丽水、桐乡、长兴、云南省', payment = payment1), Supplier(name = u'凯林瑞', display_name = u'凯林瑞', address = u'龙岗区丹竹头金鹏物流园B区D栋41-42号', phone = '0755-82432843', mobile = '', contact_person = u'杨总', remark = u'浙江嘉兴', payment = payment1), Supplier(name = u'海联', display_name = u'海联', address = u'华通源物流中心', mobile = '18688838882', contact_person = u'李老板', remark = u'宁波、义乌、绍兴、衢州、诸暨、金华、慈溪、余姚、舟山、奉化', payment = payment1), Supplier(name = u'荣晖', display_name = u'荣晖', address = u'金鹏A区B栋15-18号,40-42号', mobile = '13631528080', contact_person = u'胡总', remark = u'南昌、赣州、新余、吉安、九江、萍乡、宜春、鹰潭', payment = payment1), Supplier(name = u'深湘', display_name = u'深湘', address = u'长城货代市场83档', mobile = '13902485137', contact_person = u'丘总', remark = u'长沙、常德、衡阳、株洲、湘阴、岳阳、怀化、湘潭', payment = payment1), Supplier(name = u'澳跃', display_name = u'澳跃', address = u'金鹏', mobile = '13902311565', contact_person = u'肖总', remark = u'武汉、黄冈、黄石、荆州、咸宁、孝感、襄樊、恩施、十堰、襄阳', payment = payment1), Supplier(name = u'金鹏行', display_name = u'金鹏行', address = u'', mobile = '18926534999', contact_person = u'俞总', remark = u'合肥、淮南、黄山、桐城、芜湖、宣城、安庆、铜陵、涡阳、滁州、怀远', payment = payment1), Supplier(name = u'京鹏', display_name = u'京鹏', address = u'华通源物流中心C4栋138-152号', mobile = '13066815788', contact_person = u'傅小姐', remark = u'昆明、大理、曲靖、景洪', payment = payment1), Supplier(name = u'鑫辉', display_name = u'鑫辉', address = u'布吉丹平路闽鹏程货运市场11栋1-4号', mobile = '13925234059', contact_person = u'刘先生', remark = u'龙岩、三明', payment = payment1), Supplier(name = u'广运物流', display_name = u'广运物流', address = u'龙岗丹竹头闽鹏程货运市场5栋29-30号', mobile = '18923724600', contact_person = u'徐先生', remark = u'顺德', payment = payment1), Supplier(name = u'金华航', display_name = u'金华航', address = u'华通源物流园', phone = '0755-23022756', mobile = '', contact_person = u'刘先生', remark = u'中山', payment = payment1), Supplier(name = u'速速达', display_name = u'速速达', address = u'龙岗区布吉上李朗方鑫路22号速速达物流', phone = None, mobile = '13392831936', contact_person = u'王晓刚', remark = u'南宁、桂林、柳州、钦州', payment = payment1), Supplier(name = u'盛丰', display_name = u'盛丰', address = u'龙岗区南湾街道吉厦社区早禾坑工业区15号A栋', phone = None, mobile = '13798363667', contact_person = u'周总', remark = u'泉州、福州、莆田、福清', payment = payment1), Supplier(name = u'美泰', display_name = u'美泰', address = u'龙岗布吉大龙山物流园F栋10号美泰物流', phone = None, mobile = '18926795962', contact_person = u'毛主管', remark = u'广州', payment = payment1), Supplier(name = u'凯利', display_name = u'凯利', address = u'布吉单竹头金鹏物流园B区E栋1-5号 ', phone = '61217611,61217600', mobile = '', contact_person = u'熊小姐', remark = u'三亚、海口、琼海、万宁', payment = payment1), Supplier(name = u'骏兴顺', display_name = u'骏兴顺', address = u'龙华民治大道华通源物流中心C1栋58-60号', phone = None, mobile = '15914055308', contact_person = u'曾经理', remark = u'贵阳、金沙、安顺', payment = payment1), Supplier(name = u'澳跃', display_name = u'澳跃', address = u'金鹏A区栋13-15号', phone = None, mobile = '18923411132', contact_person = u'李峰', remark = u'漳州', payment = payment1), Supplier(name = u'勤威', display_name = u'勤威', address = u'金鹏B区C栋33号', phone = None, mobile = '13728866595', contact_person = u'石总', remark = u'厦门', payment = payment1), ]) DBSession.commit()
def review(self): id = _g('id') or None if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(self.default()) try: header = DBSession.query(OrderHeader).get(id) logs = [] logs.extend(header.get_logs()) try: deliver_detail = DBSession.query(DeliverDetail).filter(and_(DeliverDetail.active == 0, DeliverDetail.order_header_id == header.id)).one() deliver_heaer = deliver_detail.header # for f in deliver_heaer.get_logs() : _info(f.remark) logs.extend(deliver_heaer.get_logs()) except: pass logs = sorted(logs, cmp = lambda x, y: cmp(x.transfer_date, y.transfer_date)) return { 'header' : header , 'transit_logs' : logs, } except: _error(traceback.print_exc()) flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(self.default())
def save_update(self): id = _g('id', None) if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for('.view')) obj = DBSession.query(Customer).get(id) if not obj : flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('.view')) try: fields = ['no', 'name', 'display_name', 'province_id', 'city_id', 'address', 'contact_person', 'mobile', 'phone', 'email', 'note_id', 'remark'] old_info = obj.serialize(fields) # to used for the history log for f in fields: setattr(obj, f, _g(f)) #handle the file upload old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_")) old_attachment_ids.extend(multiupload()) obj.attachment = old_attachment_ids DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) # return redirect(url_for('.view',id=obj.id)) new_info = obj.serialize(fields) change_result = obj.compare(old_info, new_info) obj.insert_system_logs(change_result) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view', action = "view", id = obj.id))
def _compute_ratio(self, customer_id, province_id, city_id): qty_ratio = '' weight_ratio = '' vol_ratio = '' q1 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, CustomerDiquRatio.customer_id == customer_id, CustomerDiquRatio.province_id == province_id, CustomerDiquRatio.city_id == city_id, )) if q1.count() == 1: t = q1.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q2 = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, CustomerDiquRatio.customer_id == customer_id, CustomerDiquRatio.province_id == province_id, CustomerDiquRatio.city_id == None, )) if q2.count() == 1: t = q2.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q3 = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id)) if q3.count() == 1: t = q3.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio else: q4 = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id)) if q4.count() == 1: t = q4.one() qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # try: # t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, # CustomerDiquRatio.customer_id == customer_id, # CustomerDiquRatio.province_id == province_id, # CustomerDiquRatio.city_id == city_id, # )).one() # qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # except: # try: # t = DBSession.query(CustomerDiquRatio).filter(and_(CustomerDiquRatio.active == 0, # CustomerDiquRatio.customer_id == customer_id, # CustomerDiquRatio.province_id == province_id, # CustomerDiquRatio.city_id == None, # )).one() # qty_ratio, weight_ratio, vol_ratio = t.qty_ratio, t.weight_ratio, t.vol_ratio # except: # try: # c = DBSession.query(City).filter(and_(City.active == 0, City.id == city_id)).one() # qty_ratio, weight_ratio, vol_ratio = c.qty_ratio, c.weight_ratio, c.vol_ratio # except: # try: # p = DBSession.query(Province).filter(and_(Province.active == 0, Province.id == province_id)).one() # qty_ratio, weight_ratio, vol_ratio = p.qty_ratio, p.weight_ratio, p.vol_ratio # except: pass return {'qty_ratio' : qty_ratio, 'weight_ratio' : weight_ratio, 'vol_ratio' : vol_ratio}
def saveAsNew(clz, v): params = {} for f in ['name', 'password', 'email', 'image_url', 'phone', 'mobile', ]: params[f] = v.get(f, None) or None one = clz(**params) DBSession.add(one) return one
def saveProfile(self): uid = session['user_profile']['id'] user = DBSession.query(User).get(uid) user.mobile = _g('mobile') DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view'))
def init(): try: print "create tables" metadata.drop_all(engine, checkfirst = True) metadata.create_all(engine) print "insert default value" DBSession.add(User(name = 'demo', password = '******')) for code in range(9121, 9140): DBSession.add(NFCData(authcode = unicode(code), company = 'RoyalDragonVodka', serial = code - 9000, )) f = open('country.txt', 'r') cs = f.readlines() f.close() for c in cs: n, c, iso = c.split('|') DBSession.add(MLocation(name = n, iso_code = iso, code = c)) DBSession.commit() print "finish init!" except: traceback.print_exc() DBSession.rollback()
def getDoctorDetail(): fields = ["lang", "doctorID", "clinicID"] if _check_params(fields) != 0: return jsonify({"result": 0, "msg": MSG_PARAMS_MISSING}) lang = _g("lang") dp = DBSession.query(DoctorProfile).get(_g("doctorID")) base_info = dp.getUserProfile() c = DBSession.query(Clinic).get(_g("clinicID")) latitude = longtitude = None if c.coordinate: latitude, longtitude = c.coordinate.split(",") return jsonify( { "result": 1, "data": { "doctorID": dp.id, "name": {"zh_HK": base_info["display_name_tc"], "zh_CN": base_info["display_name_sc"]}.get( lang, base_info["display_name"] ), "desc": dp.desc, "tel": c.tel, "address": {"zh_HK": c.address_tc, "zh_CN": c.address_sc}.get(lang, c.address), "image": base_info["image_url"], "mapLocationX": longtitude, "mapLocationY": latitude, "rating": dp.rating, }, } )
def saveAsNew(clz, v): params = {} for f in clz._get_fields(): params[f] = v.get(f, None) or None obj = clz(**params) DBSession.add(obj) return obj
def saveAsNew(clz, v): params = { 'name' : v.get('name', None) or None, 'desc' : v.get('desc', None) or None, } one = clz(**params) DBSession.add(one) return one
def barcode(self): method = _g('m', 'LIST') if method not in ['LIST', 'NEW', 'PRINT', 'SAVE_NEW']: flash(MSG_NO_SUCH_ACTION, MESSAGE_ERROR); return redirect(url_for('.view', action = 'index')) DBObj = Barcode index_page = 'admin/barcode_index.html' new_page = 'admin/barcode_new.html' print_page = 'admin/barcode_print.html' action = 'barcode' if method == 'LIST': if _g('SEARCH_SUBMIT'): # come from search values = {'page' : 1} for f in ['value', 'ref_no', 'status', 'create_time_from', 'create_time_to'] : values[f] = _g(f) values['field'] = _g('field', None) or 'create_time' values['direction'] = _g('direction', None) or 'desc' else: #come from paginate or return values = session.get('master_barcode_values', {}) if _g('page') : values['page'] = int(_g('page')) elif 'page' not in values : values['page'] = 1 session['master_barcode_values'] = values conditions = [DBObj.active == 0] if values.get('value', None): conditions.append(DBObj.value.op('like')('%%%s%%' % values['value'])) if values.get('ref_no', None): conditions.append(DBObj.ref_no.op('like')('%%%s%%' % values['ref_no'])) if values.get('status', None): conditions.append(DBObj.status == values['status']) if values.get('create_time_from', None): conditions.append(DBObj.create_time > values['create_time_from']) if values.get('create_time_to', None): conditions.append(DBObj.create_time < '%s 23:59' % values['create_time_to']) field = values.get('field', 'create_time') if values.get('direction', 'desc') == 'desc': result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(desc(getattr(DBObj, field))) else: result = DBSession.query(DBObj).filter(and_(*conditions)).order_by(getattr(DBObj, field)) def url_for_page(**params): return url_for('bpAdmin.view', action = action, m = 'LIST', page = params['page']) records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = 100, url = url_for_page) return render_template(index_page, records = records, action = action, values = values) elif method == 'NEW': return render_template(new_page, action = action) elif method == 'PRINT': ids = _gl('ids') records = DBSession.query(DBObj).filter(DBObj.id.in_(ids)).order_by(desc(DBObj.create_time)) return render_template(print_page, records = records) elif method == 'SAVE_NEW': qty = _g('qty') records = [DBObj.getOrCreate(None, None, status = 1) for i in range(int(qty))] DBSession.commit() if _g('type') == 'CREATE': flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = action)) else: return render_template(print_page, records = records)
def saveAsNew(clz, v): params = { "name" : v.get("name", None) or None, "desc" : v.get("desc", None) or None, "display_name" : v.get("display_name", None) or None } group = clz(**params) DBSession.add(group) return group
def saveAsNew(clz, v): params = {} for f in ['name', 'code', 'province_id', 'city_id', 'begin_no', 'end_no', 'apply_time', 'apply_person_id', 'operator_id', 'remark']: params[f] = v.get(f, None) or None obj = clz(**params) DBSession.add(obj) return obj
def profit(self): if _g('SEARCH_SUBMIT'): # come from search values = {'page' : 1} for f in [ 'no', 'create_time_from', 'create_time_to', 'destination_province_id', 'destination_city_id', 'ref_no', 'deliver_no', 'supplier_id', 'payment_id', 'is_discount_return' ] : values[f] = _g(f) values['field'] = _g('field', None) or 'create_time' values['direction'] = _g('direction', None) or 'desc' else: # come from paginate or return values = session.get('fin_profit_values', {}) if _g('page') : values['page'] = int(_g('page')) elif 'page' not in values : values['page'] = 1 if not values.get('create_time_from', None) and not values.get('create_time_to', None): values['create_time_to'] = dt.now().strftime("%Y-%m-%d") values['create_time_from'] = (dt.now() - timedelta(days = 30)).strftime("%Y-%m-%d") session['fin_profit_values'] = values conditions = [OrderHeader.active == 0, DeliverHeader.active == 0 , DeliverDetail.active == 0, DeliverHeader.id == DeliverDetail.header_id, OrderHeader.id == DeliverDetail.order_header_id, ] if values.get('create_time_from', None): conditions.append(OrderHeader.order_time > values['create_time_from']) if values.get('create_time_to', None): conditions.append(OrderHeader.order_time < '%s 23:59' % values['create_time_to']) if values.get('ref_no', None): conditions.append(OrderHeader.ref_no.op('like')('%%%s%%' % values['ref_no'])) if values.get('deliver_no', None): conditions.append(DeliverHeader.no.op('like')('%%%s%%' % values['deliver_no'])) if values.get('destination_province_id', None): conditions.append(OrderHeader.destination_province_id == values['destination_province_id']) dp = DBSession.query(Province).get(values['destination_province_id']) destination_cites = dp.children() else: destination_cites = [] if values.get('destination_city_id', None): conditions.append(OrderHeader.destination_city_id == values['destination_city_id']) if values.get('supplier_id', None): conditions.append(DeliverHeader.supplier_id == values['supplier_id']) if values.get('payment_id', None): conditions.append(OrderHeader.payment_id == values['payment_id']) if values.get('is_discount_return', None): conditions.append(OrderHeader.is_discount_return == values['is_discount_return']) # for the sort function field = values.get('field', 'create_time') if values.get('direction', 'desc') == 'desc': result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions)) else: result = DBSession.query(OrderHeader, DeliverHeader).filter(and_(*conditions)) def url_for_page(**params): return url_for('bpFin.view', action = "profit", page = params['page']) records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page) return { 'values' : values , 'records' : records, 'destination_cites' : destination_cites, }
def _save_new(self): try: result = self.dbObj.save_new(self) DBSession.commit() self.flash("Save the record successfully!") except Exception as e: DBSession.rollback() self.flash(getattr(e, "msg", None) or "This operation is not available now!") self._new() self.redirect("%s?action=view&id=%d" % (self.url_prefix, result.id))
def save_new(clz, handler): params = { "user_name" : handler.get_argument("user_name", None), "email_address" : handler.get_argument("email_address", None), "display_name" : handler.get_argument("display_name", None), "password" : handler.get_argument("password", None), } record = clz(**params) DBSession.add(record) return record
def save_events(): uid = request.values.get("uid", None) did = request.values.get("did", None) d = request.values.get("d", None) t = request.values.get("t", None) if not uid or not did or not d or not t: return jsonify({"success": False, "message": "The required info is not supplied !"}) format_date = lambda v: "-".join([v[:4], v[4:6], v[-2:]]) try: e = Events(user_id=uid, doctor_id=did, date=d, time=t, remark=request.values.get("remark", None)) DBSession.add(e) doctor = DBSession.query(DoctorProfile).get(did).getUserProfile() m = Message( subject=u"Booking request submit", user_id=session["user_profile"]["id"], content=u"%s make a booking with doctor %s at %s , %s." % (session["user_profile"]["name"], doctor["name"], t, format_date(d)), ) DBSession.add(m) DBSession.commit() return jsonify({"success": True, "message": "Save your request successfully !", "event_time": e.time}) except: DBSession.rollback() app.logger.error(traceback.format_exc()) return jsonify({"success": False, "message": "Error occur when submiting the request !"})
def save_new(self): params = { "name" : _g('name'), "address" : _g('address'), "manager" : _g('manager'), "remark" : _g('remark'), "parent_id" : _g('parent_id'), } try: obj = InventoryLocation(**params) DBSession.add(obj) DBSession.flush() if params['parent_id']: parent = DBSession.query(InventoryLocation).get(obj.parent_id) obj.full_path = "%s%s" % (parent.full_path or '', params['name']) obj.full_path_ids = "%s|%s" % (parent.full_path_ids, obj.id) else: obj.full_path = params['name'] obj.full_path_ids = obj.id DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) except: DBSession.rollback() _error(traceback.print_exc()) return redirect(self.default())
def m_events_update(): id = _g("id") if not id : flash("No id supplied !", MESSAGE_ERROR) return redirect(url_for("m_events_list")) action_type = _g("action_type") if not action_type in ["m", "c", "p"]: flash("No such action !", MESSAGE_ERROR) return redirect(url_for("m_events_list")) e = DBSession.query(Events).get(id) # e = connection.Events.one({"id" : int(id)}) if action_type == "m": return render_template("m_events_update.html", event = e) elif action_type == "c": #cancel e.status = 2 DBSession.add(Message(subject = u"Cancel Booking Event", user_id = e.user_id, content = u"%s cancel the booking request." % session['user_profile']['name'])) DBSession.commit() return jsonify({"success" : True, "message" : "Update successfully !"}) elif action_type == "p": #confirmed e.status = 1 DBSession.add(Message(subject = u"Confirm Booking Event", user_id = e.user_id, content = u"%s confirm the booking request." % session['user_profile']['name'])) DBSession.commit() return jsonify({"success" : True, "message" : "Update successfully !"})
def _save_update(self): try: result = self.dbObj.save_update(self.get_argument("id", None), self) DBSession.commit() self.flash("Save the record successfully!") except Exception as e: logging.error(traceback.print_exc()) DBSession.rollbak() self.flash(getattr(e, "msg", None) or "This operation is not available now!") self._update() self.redirect("%s?action=view&id=%d" % (self.url_prefix, result.id))
def delete(self): header = getOr404(OrderHeader, _g('id'), redirect_url = self.default()) header.active = 1 DBSession.add(SystemLog( type = header.__class__.__name__, ref_id = header.id, remark = u"%s 删除该记录。" % session['user_profile']['name'], )) DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'index'))
def view_items(self): id = _g('id') w = DBSession.query(InventoryLocation).get(id) ids = w.full_path_ids.split("|") result = DBSession.query(InventoryItem, InventoryLocation).filter(and_( InventoryItem.active == 0, InventoryItem.location_id.in_(ids), InventoryLocation.active == 0, InventoryItem.location_id == InventoryLocation, )).order_by(InventoryItem.create_time).all() return {'result' : result , 'location' : w}
def list_doctors(): id = request.values.get("id", None) if not id: dps = DBSession.query(DoctorProfile).filter(DoctorProfile.active == 0) # dps = connection.DoctorProfile.find({'active':0}) data = [dp.populate() for dp in dps] else: c = DBSession.query(Clinic).get(id) # c = connection.Clinic.one({'active':0, 'id':int(id)}) # data = [connection.DoctorProfile.one({'id':i}).populate() for i in c.doctors] data = [i.populate() for i in c.doctors] return {"doctors": data}
def delete(self): id = _g('id', None) if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for('.view')) obj = DBSession.query(Customer).get(id) if not obj : flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('.view')) obj.active = 1 DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) return redirect(url_for('.view'))
def in_note(self): if _g('SEARCH_SUBMIT'): # come from search values = {'page' : 1} for f in ['no', 'create_time_from', 'create_time_to', 'customer_id', 'location_id' ] : values[f] = _g(f) values['field'] = _g('field', None) or 'create_time' values['direction'] = _g('direction', None) or 'desc' else: # come from paginate or return values = session.get('inventory_in_note_values', {}) if _g('page') : values['page'] = int(_g('page')) elif 'page' not in values : values['page'] = 1 if not values.get('create_time_from', None) and not values.get('create_time_to', None): values['create_time_to'] = dt.now().strftime("%Y-%m-%d") values['create_time_from'] = (dt.now() - timedelta(days = 30)).strftime("%Y-%m-%d") session['inventory_in_note_values'] = values conditions = [InventoryInNote.active == 0] if values.get('create_time_from', None): conditions.append(InventoryInNote.create_time > values['create_time_from']) if values.get('create_time_to', None): conditions.append(InventoryInNote.create_time < '%s 23:59' % values['create_time_to']) if values.get('no', None): conditions.append(InventoryInNote.no.op('like')('%%%s%%' % values['no'])) if values.get('customer_id', None): conditions.append(InventoryInNote.customer_id == values['customer_id']) if values.get('location_id', None): conditions.extend([ InventoryNoteDetail.active == 0, InventoryNoteDetail.type == 'IN', InventoryNoteDetail.header_id == InventoryInNote.id, InventoryNoteDetail.location_id == values['location_id'], ]) # for the sort function field = values.get('field', 'create_time') if values.get('direction', 'desc') == 'desc': result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(desc(getattr(InventoryInNote, field))) else: result = DBSession.query(InventoryInNote).filter(and_(*conditions)).order_by(getattr(InventoryInNote, field)) def url_for_page(**params): return url_for('.view', action = "in_note", page = params['page']) records = paginate.Page(result, values['page'], show_if_single_page = True, items_per_page = PAGINATE_PER_PAGE, url = url_for_page) root_locations = DBSession.query(InventoryLocation).filter(and_(InventoryLocation.active == 0, InventoryLocation.parent_id == None)).order_by(InventoryLocation.name) return { 'values' : values , 'records' : records, 'locations' : root_locations, }
def saveNewArticle(self): appid, title, sub_title, validate_date, desc, content = _gs('appid', 'title', 'sub_title', 'validate_date', 'desc', 'content') if not appid : flash(MSG_NO_ID_SUPPLIED, MESSAGE_WARNING) return redirect(url_for('.view')) if not title: flash(MSG_NO_ENOUGH_PARAMS, MESSAGE_WARNING) return redirect(url_for('.view', action = 'createArticle', appid = appid)) try: article = AppArticle( app_id = appid, title = title, sub_title = sub_title, desc = desc, content = content, validate_date = validate_date, ) DBSession.add(article) DBSession.flush() article.seq = article.id DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for(".view", action = "listArticle", appid = appid)) except: DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) traceback.print_exc() return redirect(url_for(".view", action = "listArticle", appid = appid))
def out_note_delete(self): id = _g("id") if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for(".view", action = "out_note")) try: note = DBSession.query(InventoryOutNote).get(id) note.active = 1 for d in note.details: location_item = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.active == 0, InventoryLocationItem.location_id == d.location_id, InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one() if note.status == 1 : # the record is not approved location_item.qty += d.qty location_item.area += d.area location_item.weight += d.weight location_item.exp_qty += d.qty location_item.exp_area += d.area location_item.exp_weight += d.weight DBSession.add(SystemLog( type = InventoryOutNote.__class__.__name__, ref_id = note.id, remark = u"%s 删除该记录。" % (session['user_profile']['name']) )) DBSession.commit() flash(MSG_DELETE_SUCC, MESSAGE_INFO) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for(".view", action = "out_note"))
def getOrCreate(clz, value, ref_no, status = 0): if value: # get the existing try: b = DBSession.query(clz).filter(clz.value == value).one() return b except: pass #create b = clz(value = value, ref_no = ref_no, status = status) DBSession.add(b) DBSession.flush() b.value = '%s%06d' % (dt.now().strftime('%y%m%d'), (b.id % 1000000)) b.img = generate_barcode_file(b.value) return b
def out_note_save_update(self): id = _g('id') if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for(".view", action = "out_note")) obj = DBSession.query(InventoryOutNote).get(id) for f in ['customer_id', 'so', 'po', 'dn', 'ref', 'remark' ] : setattr(obj, f, _g(f)) total_qty = total_weight = total_area = 0 details_mapping = {} for d in obj.details : details_mapping['%s' % d.id] = d for qk, qv in _gp("qty_"): id = qk.split("_")[1] if id not in details_mapping : continue d = details_mapping[id] qty = self._p(_g('qty_%s' % id), int, 0) weight = self._p(_g('weight_%s' % id), float, 0) area = self._p(_g('area_%s' % id), float, 0) total_qty += qty total_area += area total_weight += weight if obj.status != 2: # update the locaion-item relation t = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.location_id == d.location_id, InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one() if obj.status == 1: # if the record is approved,update the real qty/weight/area t.qty -= qty - d.qty t.weight -= weight - d.weight t.area -= area - d.area t.exp_qty -= qty - d.qty t.exp_weight -= weight - d.weight t.exp_area -= area - d.area d.qty = qty d.weight = weight d.area = area obj.qty = total_qty obj.area = total_area obj.weight = total_weight DBSession.commit() flash(MSG_UPDATE_SUCC, MESSAGE_INFO) return redirect(url_for(".view", action = "out_note_review", id = obj.id))
def check(): try: u = DBSession.query(User).filter(and_(User.active == 0, User.name == _g('name'))).one() except: _error(traceback.print_exc()) flash(MSG_USER_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('bpAuth.login', next = _g('next'))) else: if not _g('password'): flash(MSG_WRONG_PASSWORD, MESSAGE_ERROR) return redirect(url_for('bpAuth.login', next = _g('next'))) if not u.validate_password(_g('password')): flash(MSG_WRONG_PASSWORD, MESSAGE_ERROR) return redirect(url_for('bpAuth.login', next = _g('next'))) else: #fill the info into the session session['login'] = True session['user_profile'] = u.populate() permissions = set() for g in u.groups: for p in g.permissions: permissions.add(p.name) session['user_profile']['groups'] = [g.name for g in u.groups] session['user_profile']['permissions'] = list(permissions) if in_group('CUSTOMER'): for g in u.groups: if g.type != 0 : for p in g.customer_profile: if p and p.customer_id: session['customer_profile'] = p.customer.populate() break if in_group('SUPPLIER'): for g in u.groups: if g.type != 0 : for p in g.supplier_profile: if p and p.supplier_id: session['supplier_profile'] = p.supplier.populate() break u.last_login = dt.now() session.permanent = True DBSession.commit() if _g('next') : return redirect(_g('next')) return redirect(index_url())