def get_product_locations(product_id,sku_id=None,opn=False,session=None): if not session: session = get_session() params = {'product_id':product_id} if sku_id: params['sku_id'] = sku_id locations = session.query(ProductLocation).filter_by(**params) sdict = {} for d in locations: dno = d.district.district_no pno = d.district.parent_no if sdict.has_key(pno): sdict[pno].add(dno) else: sdict[pno] = set([dno]) if opn : pnos = sdict.keys() pnos.sort() return ''.join(pnos) ds = [] for k,v in sdict.iteritems(): ds.append(len(v) > 1 and '%s-[%s]'%(k,','.join(list(v))) or '%s-%s'%(k,v.pop())) return ','.join(ds)
def get_datasource_by_type_and_mode(status_type,print_mode=pcfg.NORMAL_MODE,session=None): """ 获取交易数据源 """ if not session: session = get_session() datasource = session.query(PackageOrder) counter = session.query(func.count(PackageOrder.id)) seller_ids = get_seller_ids() if seller_ids: datasource = datasource.filter(PackageOrder.seller_id.in_(seller_ids)) counter = counter.filter(PackageOrder.seller_id.in_(seller_ids)) ware_id = get_ware_id() if int(ware_id) == 1: datasource = datasource.filter(PackageOrder.ware_by.in_([1, 3])) counter = counter.filter(PackageOrder.ware_by.in_([1, 3])) else: datasource = datasource.filter_by(ware_by=ware_id) counter = counter.filter_by(ware_by=ware_id) if status_type and status_type != pcfg.SYS_STATUS_ALL: datasource = datasource.filter_by(sys_status=status_type) counter = counter.filter_by(sys_status=status_type) print 'debug:',ware_id,seller_ids datasource = datasource.order_by(PackageOrder.pid, 'priority desc','pid asc') return datasource,counter
def __init__(self, parent): self.parent = parent if hasattr(parent, 'Session'): self.session = parent.Session else: from taobao.dao.dbsession import get_session self.session = get_session()
def __init__(self, parent, id=-1, title=TITLE, pos=wx.DefaultPosition, size=(1300,700), style=wx.DEFAULT_FRAME_STYLE |wx.SUNKEN_BORDER |wx.CLIP_CHILDREN): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.Session = get_session() # tell FrameManager to manage this frame self._mgr = wx.aui.AuiManager() self._mgr.SetManagedWindow(self) # create menu mb = wx.MenuBar() view_menu = wx.Menu() view_menu.Append(ID_TradeMainPage, u"订单列表",u"订单操作主界面") view_menu.Append(ID_ScanCheck, u"扫描验货",u"扫描物流单编号,扫描商品条码") view_menu.Append(ID_ScanWeight, u"扫描称重",u"扫描物流单编号,包裹称重") #view_menu.Append(ID_ScanCharge, u"揽件确认",u"扫描物流单编号,确认揽件") view_menu.Append(wx.ID_EXIT, u"退出") view_menu.AppendSeparator() help_menu = wx.Menu() help_menu.Append(ID_Help, u"帮助文档") mb.Append(view_menu, u"订单操作") mb.Append(help_menu, u"帮助") self.SetMenuBar(mb) self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP) self.statusbar.SetStatusWidths([-2, -3]) self.statusbar.SetStatusText("Ready", 0) #self.statusbar.SetStatusText("Welcome To wxPython!", 1) self.SetMinSize(wx.Size(400, 300)) self._mgr.AddPane(self.CreateOrderGrid(), wx.aui.AuiPaneInfo().Name("order_grid_content"). CenterPane().Hide()) self._mgr.AddPane(self.CreateCheckView(), wx.aui.AuiPaneInfo().Name("scan_check_content"). CenterPane().Hide()) self._mgr.AddPane(self.CreateDeliveryView(), wx.aui.AuiPaneInfo().Name("scan_weight_content"). CenterPane().Hide()) # self._mgr.AddPane(self.CreateChargeView(), wx.aui.AuiPaneInfo().Name("scan_charge_content"). # CenterPane().Hide()) all_panes = self._mgr.GetAllPanes() for ii in xrange(len(all_panes)): all_panes[ii].Hide() self._mgr.GetPane("order_grid_content").Show() self._mgr.Update() self.Bind(wx.EVT_MENU, self.OnChangeContentPane, id=ID_TradeMainPage) self.Bind(wx.EVT_MENU, self.OnChangeContentPane, id=ID_ScanCheck) self.Bind(wx.EVT_MENU, self.OnChangeContentPane, id=ID_ScanWeight) # self.Bind(wx.EVT_MENU, self.OnChangeContentPane, id=ID_ScanCharge) self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
def get_zone_by_code(code, session=None): """ 根据编码获取网点及分拨中心 """ if not session: session = get_session() czones = session.query(BranchZone).filter_by(barcode=code) return czones.first()
def is_normal_print_limit(session=None): if not session: session = get_session() try: sys_config = session.query(SystemConfig).first() except: return True else: return sys_config.normal_print_limit
def __enter__(self): from taobao.dao.models import SystemConfig from taobao.dao.dbsession import get_session try: self.session.query(SystemConfig).first() except: self.session = get_session() self.parent.Session = self.session return self.session
def get_per_request_num(session=None): per_request_num = 1 if not session: session = get_session() try: sys_config = session.query(SystemConfig).first() except: pass else: per_request_num = sys_config.per_request_num return per_request_num>0 and per_request_num or 1
def locking_trade(trade_id,operator,session=None): """ 锁定交易 """ from taobao.dao.webapi import WebApi if not session: session = get_session() is_locked = False trade = session.query(PackageOrder).filter_by(pid=trade_id).first() if not trade.is_locked: WebApi.operate_packages([trade.id], operator) elif trade.operator == operator: is_locked = True return is_locked
''' Created on 2012-6-2 @author: user1 ''' from taobao.dao.dbsession import get_session from taobao.dao.models import Trade, Order session = get_session() #trade = session.query(Trade).filter_by(status='TRADE_FINISHED').first() #trade = session.query(Trade).filter_by(status='TRADE_FINISHED').one() trade = session.query(Trade).get(173863640941048) print trade print trade.orders