def getLogisticsData(self, trade_ids=[]): with create_session(self.Parent) as session: send_trades = session.query(PackageOrder).filter( PackageOrder.pid.in_(trade_ids)).order_by('out_sid') express_data_list = [] for trade in send_trades: trade_data = {} dt = datetime.datetime.now() trade_data['trade_id'] = trade.pid trade_data['seller_nick'] = trade.user.nick trade_data['seller_contacter'] = trade.user.contacter trade_data['seller_phone'] = trade.user.phone trade_data['seller_mobile'] = trade.user.mobile trade_data['seller_area_code'] = trade.user.area_code trade_data['seller_location'] = trade.user.location trade_data['post_date'] = dt trade_data['buyer_nick'] = trade.buyer_nick trade_data['out_sid'] = trade.out_sid trade_data['company_name'] = (trade.logistics_company and trade.logistics_company.name or 'NULL') trade_data['company_code'] = (trade.logistics_company and trade.logistics_company.code or 'NULL') trade_data['receiver_name'] = trade.receiver_name trade_data['receiver_phone'] = trade.receiver_phone trade_data['receiver_mobile'] = trade.receiver_mobile trade_data['receiver_zip'] = trade.receiver_zip trade_data['receiver_state'] = trade.receiver_state trade_data['receiver_city'] = trade.receiver_city trade_data['receiver_district'] = trade.receiver_district trade_data['receiver_address'] = trade.receiver_address trade_data['zone'] = '' if trade_data['company_code'].upper() in YUNDA_CODE: zone = None # if trade.is_qrcode and trade.reserveo: # zone = get_zone_by_code(trade.reserveo,session=session) if not zone: zone = get_classify_zone( trade.receiver_state, trade.receiver_city, trade.receiver_district, address=trade.receiver_address, session=session) trade_data['zone'] = zone and '%s %s' % ( zone['name'], zone['code']) or '' express_data_list.append(trade_data) return express_data_list
def __set_properties(self): self.SetName('search_panel') with create_session(self.Parent) as session: users = session.query(User).all() logistics_companies = session.query(LogisticsCompany).filter_by(status=True).order_by('priority desc').all() self.seller_select.AppendItems([user.nick for user in users]) self.logistics_company_select.AppendItems([u'全部'] + [company.name for company in logistics_companies]) self.logistics_company_select.SetSelection(0) self.taobao_status_select.AppendItems([v for k, v in cfg.TRADE_STATUS.items()]) self.trade_type_select.AppendItems([v for k, v in cfg.TRADE_TYPE.items()]) self.trade_type_select.SetSelection(2)
def __set_properties(self): self.SetName('charge panel') with create_session(self.Parent) as session: logistics_companies = session.query(LogisticsCompany).filter_by( status=True).order_by('priority desc').all() self.company_select.AppendItems( [company.name for company in logistics_companies]) self.company_select.SetFocus() self.charge_start_select.SetValue( pydate2wxdate(datetime.datetime.now())) self.out_sid_text.Enable(False)
def createHtml(self,trade_ids=[]): ''' Creates an html file in the home directory of the application that contains the information to display the snapshot ''' with create_session(self.Parent) as session: trade_user_code = session.query(PackageOrder).filter_by(pid=trade_ids[0])\ .one().user.user_code.lower() trades = self.getTradePickingData(trade_ids) try: template = get_template('invoice/invoice_%s_template.html'%trade_user_code) html =template.render(trades=trades) except: return u'<center>模板异常</center>' return html
def onComboboxSelect(self, evt): company_name = self.company_select.GetValue().strip() charge_start_date = self.charge_start_select.GetValue() charge_end_date = self.charge_end_select.GetValue() dt = datetime.datetime.now() charge_start_date = wxdate2pydate(charge_start_date) or dt.date() charge_end_date = wxdate2pydate(charge_end_date) self.out_sid_text.Enable(charge_start_date.day == dt.day) if (dt.date() - charge_start_date).days > 7: dial = wx.MessageDialog(None, u'查询日期须在7日内', u'快递揽件信息确认提示', wx.OK | wx.ICON_EXCLAMATION) dial.ShowModal() return with create_session(self.Parent) as session: logistics_company = session.query(LogisticsCompany).filter_by( name=company_name).first() if not logistics_company: dial = wx.MessageDialog(None, u'未找到快递信息', u'快递揽件信息确认提示', wx.OK | wx.ICON_EXCLAMATION) dial.ShowModal() return charge_trades = session.query(PackageOrder).filter_by( is_picking_print=True, is_express_print=True, logistics_company_id=logistics_company.id, sys_status=cfg.SYS_STATUS_FINISHED, is_charged=True) if charge_start_date: charge_trades = charge_trades.filter( "charge_time >=:start").params(start=charge_start_date) if charge_end_date: charge_trades = charge_trades.filter( "charge_time <=:end").params(end=charge_end_date) self.set_datasource(charge_trades) evt.Skip()
def printPromptOk(self): with create_session(self.Parent) as session: trades = session.query(PackageOrder).filter(PackageOrder.pid.in_(self.trade_ids)).filter_by(is_picking_print=True) rept_num = trades.count() if rept_num > 0: dial = wx.MessageDialog(None, u'该批订单有(%d)单已打印发货单,还要继续吗?'%rept_num, u'发货单重打提示', wx.OK|wx.CANCEL|wx.ICON_EXCLAMATION) result = dial.ShowModal() dial.Destroy() #如果不继续,则退出 if result != wx.ID_OK: return False WebApi.print_express(self.trade_ids) # session.query(PackageOrder).filter(PackageOrder.pid.in_(self.trade_ids))\ # .update({'is_picking_print':True},synchronize_session='fetch') self.printed = True return True
def onPreview(self, event): """""" with create_session(self.Parent) as session: trades = session.query(PackageOrder).filter( PackageOrder.pid.in_( self.trade_ids)).filter_by(is_express_print=True) rept_num = trades.count() if rept_num > 0: dial = wx.MessageDialog( None, u'该批订单有(%d)单已打印快递单,还要继续吗?' % rept_num, u'快递单重打提示', wx.OK | wx.CANCEL | wx.ICON_EXCLAMATION) result = dial.ShowModal() dial.Destroy() # 如果不继续,则退出 if result != wx.ID_OK: return WebApi.print_express(self.trade_ids) self.printed = True updatePageSetupRegedit(self.getPageSetup()) self.html.PrintPreview() event.Skip()
def appendFilter(datasource): if trade_id: datasource = datasource.filter(or_(PackageOrder.pid == trade_id, PackageOrder.id == trade_id)) elif logistics_id: datasource = datasource.filter_by(out_sid=getSid(logistics_id), action_type=trade_type.strip()) else: if trade_type: if trade_type == u'特殊': datasource = datasource.filter_by(action_type=1) elif trade_type == u'普通': datasource = datasource.filter_by(action_type=0) if trade_status: status_dict = dict([(v, k) for k, v in cfg.TRADE_STATUS.items()]) datasource = datasource.filter_by(status=status_dict.get(trade_status.strip(), None)) if seller_id: datasource = datasource.join(User).filter(User.nick == seller_id.strip()) if start_time: datasource = datasource.filter("pay_time >=:start").params(start=start_time) if end_time: datasource = datasource.filter("pay_time <=:end").params(end=end_time) if weight_start_time: datasource = datasource.filter("weight_time >=:start").params(start=weight_start_time) if weight_end_time: datasource = datasource.filter("weight_time <=:end").params(end=weight_end_time) if logistics_company: if logistics_company != u'全部': with create_session(self.Parent) as session: log_company = session.query(LogisticsCompany).filter_by(name=logistics_company.strip()).one() datasource = datasource.filter(PackageOrder.logistics_company_id == log_company.id) if urgent_doc_state: datasource = datasource.filter_by(priority=1) if single_prod: datasource = datasource.filter(PackageOrder.prod_num == 1) if pick_print_state: datasource = datasource.filter_by(is_picking_print=pick_print_state == 1 and True or False) if express_print_state: datasource = datasource.filter_by(is_express_print=express_print_state == 1 and True or False) if juhuasuan: if juhuasuan == 1: datasource = datasource.filter_by(ready_completion=True) if outer_id: trade_ids = [t.id for t in datasource] with create_session(self.Parent) as session: merge_orders = session.query(PackageSkuItem).filter( PackageSkuItem.merge_trade_id.in_(trade_ids)) if outer_id and sku_outer_id: merge_orders = merge_orders.filter(PackageSkuItem.outer_id == outer_id, PackageSkuItem.outer_sku_id == sku_outer_id) else: merge_orders = merge_orders.filter(PackageSkuItem.outer_id == outer_id) trade_ids = set([o.merge_trade_id for o in merge_orders]) datasource = session.query(PackageSkuItem).filter(PackageSkuItem.id.in_(trade_ids)) if locke_state: datasource = datasource.filter_by(is_locked=locke_state == 1 and True or False) datasource.order_by('merged') return datasource
def getTradePickingData(self ,trade_ids=[]): with create_session(self.Parent) as session: send_trades = session.query(PackageOrder).filter(PackageOrder.pid.in_(trade_ids)).order_by('out_sid') dt = datetime.datetime.now() picking_data_list = [] for trade in send_trades: trade_data = {} trade_data['trade_id'] = trade.id trade_data['seller_nick'] = trade.user.nick trade_data['post_date'] = dt trade_data['pay_time'] = trade.pay_time trade_data['buyer_nick'] = trade.buyer_nick trade_data['out_sid'] = trade.out_sid trade_data['company_name'] = trade.logistics_company and trade.logistics_company.name trade_data['order_nums'] = 0 trade_data['total_fee'] = 0 trade_data['discount_fee'] = 0 trade_data['payment'] = 0 trade_data['buyer_prompt'] = '' trade_data['juhuasuan'] = trade.trade_from&JUHUASUAN_CODE == JUHUASUAN_CODE trade_data['receiver_name'] = trade.receiver_name trade_data['receiver_phone'] = trade.receiver_phone trade_data['receiver_mobile'] = trade.receiver_mobile trade_data['receiver_state'] = trade.receiver_state trade_data['receiver_city'] = trade.receiver_city trade_data['receiver_district'] = trade.receiver_district trade_data['receiver_address'] = trade.receiver_address trade_data['buyer_message'] = trade.buyer_message trade_data['seller_memo'] = trade.seller_memo trade_data['sys_memo'] = trade.sys_memo trade_data['buyer_prompt'] = '' prompt_set = set() order_items = {} orders = get_used_orders(session,trade.id) for order in orders: trade_data['order_nums'] += order.num trade_data['discount_fee'] += float(order.discount_fee or 0) trade_data['total_fee'] += float(order.total_fee or 0) trade_data['payment'] += float(order.payment or 0) outer_id = order.outer_id or str(order.num_iid) outer_sku_id = order.outer_sku_id or str(order.sku_id) product = session.query(Product).filter_by(outer_id=order.outer_id).first() prod_sku = session.query(ProductSku).filter_by(outer_id=order.outer_sku_id,product=product).first() product_id = product and product.id or '' sku_id = prod_sku and prod_sku.id or '' promptmsg = (prod_sku and prod_sku.buyer_prompt) or (product and product.buyer_prompt) or '' if promptmsg: prompt_set.add(promptmsg) if order_items.has_key(outer_id): order_items[outer_id]['num'] += order.num skus = order_items[outer_id]['skus'] if skus.has_key(outer_sku_id): skus[outer_sku_id]['num'] += order.num else: prod_sku_name = prod_sku and prod_sku.name or order.sku_properties_name skus[outer_sku_id] = {'sku_name':prod_sku_name, 'num':order.num, 'location':get_product_locations(product_id,sku_id,session=session)} else: prod_sku_name = prod_sku and prod_sku.name or order.sku_properties_name order_items[outer_id]={ 'num':order.num, 'location':get_product_locations(product_id,opn=True,session=session), 'title': product.name if product else order.title, 'skus':{outer_sku_id:{'sku_name':prod_sku_name, 'num':order.num, 'location':get_product_locations(product_id,sku_id,session=session)}} } trade_data['buyer_prompt'] = prompt_set and ','.join(list(prompt_set)) or '' order_list = sorted(order_items.items(),key=lambda d:d[1]['location']) for trade in order_list: skus = trade[1]['skus'] trade[1]['skus'] = sorted(skus.items(),key=lambda d:d[1]['location']) trade_data['orders'] = order_list picking_data_list.append(trade_data) return picking_data_list
def getTradeUserCode(self,trade_ids): with create_session(self.Parent) as session: trade_user_code = session.query(PackageOrder).filter_by(pid=trade_ids[0])\ .one().seller.user_code.lower() return trade_user_code