def _process_pac(self): wb = YRWorkbook(self.filename) names = wb.get_sheet_names() for name in names: wb.pin_sheet_by_name(name) self.logger.debug(name) nrows = wb.get_nrows() for ind in xrange(self.START_ROW,nrows): pn = wb.get_cell_value(self.PN_COL + str(ind)) pcs = wb.get_cell_value(self.PCS_COL + str(ind)) nw = wb.get_cell_value(self.NW_COL + str(ind)) gw = wb.get_cell_value(self.GW_COL + str(ind)) end_tag = wb.get_cell_value(self.END_TAG_COL + str(ind)).lower() pcs = int(pcs) nw = float(nw) gw = float(gw) #print type(pcs) if pcs <= 0 or nw <= 0 or gw <= 0: utils.ABT(u"ERROR: PAC 中,这条记录(pn=%s,pcs=%d,nw=%f,gw=%f)存在错误" %(pn,pcs,nw,gw)) if not end_tag.find(self.END_STR): self._get_plt(wb,self.PLT_COL+str(ind)) break self.logger.debug("%s, %d, %f, %f, %s", pn, pcs, nw, gw,end_tag) if not self.data.has_key(pn): self.data[pn] = {self.PCS: 0, self.NW:0.0, self.GW:0.0} self.data[pn][self.PCS] += pcs self.data[pn][self.NW] += nw self.data[pn][self.GW] += gw
def _process(self): names = self.wb.get_sheet_names() for name in names: #print name ws = self.wb.get_sheet_by_name(name) for row in xrange(1, ws.max_row + 1): pn = ws["A" + str(row)].value qty = ws["B" + str(row)].value uprice = ws["C" + str(row)].value if pn is None or qty is None or uprice is None: continue pn.strip() if pn == self.HEADER: continue qty = int(qty) uprice = float(uprice) if qty <= 0 or uprice <= 0: utils.ABT( u"ERROR: 出口表中,这条记录(pn=%s,qty=%d,unit_price=%f) 有错误" % (pn, qty, uprice)) if not self.db.has_key(pn): self.db[pn] = [0, 0] self.db[pn][0] = max(self.db[pn][0], uprice) self.db[pn][1] += qty
def __init__(self,filename,**kwargs): self.filename = filename self.logger = logging.getLogger("InfoDB") try: self.wb = load_workbook(filename,use_iterators=True) except IOError: utils.ABT(u"规范申报数据库文件缺失") try: self.sheet = self.wb.get_sheet_by_name("DATA") except KeyError: utils.ABT(u"规范申报数据库中缺失 DATA 表单") self.data = {} #each is a dict for row in xrange(1,self.sheet.max_row+1): pn = self.sheet["A"+str(row)].value model = self.sheet["B"+str(row)].value code = self.sheet["C"+str(row)].value desc = self.sheet["D"+str(row)].value if pn is None or model is None or code is None or desc is None: self.logger.debug(u"在规范数据库缺失") continue pn.strip() model.strip() desc.strip() if pn == self.HEADER: continue if self.data.has_key(pn): #if self.data[pn][self.MODEL] == model and self.data[pn][self.CODE] == code and self.data[pn][self.DESC] == desc: continue """ else: print("duplicate PN(%s) in database file" % pn) print "model=", model print self.data[pn][self.MODEL] print "code=",code print self.data[pn][self.CODE] print "desc=", desc print self.data[pn][self.DESC] assert 0 """ #assert not self.data.has_key(pn), (u"(%s) is duplicate in database table(%s)" %(pn,self.filename)) self.data[pn] = {} self.data[pn][self.MODEL] = model self.data[pn][self.CODE] = code self.data[pn][self.DESC] = desc
def __init__(self, filename, **kwargs): self.filename = filename try: self.wb = load_workbook(filename) except IOError: utils.ABT(u"ERROR: 出口文件缺失") self.db = {} #[0,0],,,max_price, qty self._process()
def process_pac(self, pac_info, **kwargs): pns = self.data.keys() if len(pns) != len(self.data.keys()): utils.ABT(u"ERROR: TPI 与 PAC P/N 不一致") for pn in pns: pac_pcs = pac_info.get_pcs(pn) pac_nw = pac_info.get_nw(pn) pac_gw = pac_info.get_gw(pn) #print "pac_pcs=",pac_pcs, " pac_nw=", pac_nw," pac_gw", pac_gw, " qty=",self.data[pn][self.QTY] if pac_pcs is None: utils.ABT(u"ERROR: TPI 与 PAC P/N 不一致!") if pac_pcs != self.data[pn][self.QTY]: self.ok = False utils.ABT(u"ERROR: TPI 与 PAC QTY 不一致!") return False self.data[pn][self.NW] = pac_nw self.data[pn][self.GW] = pac_gw return True
def __init__(self, tpi_info, ex_info, **kwargs): self.data = {} #None self.ok = True self.logger = logging.getLogger(str(self.__class__)) self.logger.setLevel(utils.LOG_LEVEL) tpi_pns = tpi_info.get_pns() ex_pns = ex_info.get_pns() if len(tpi_pns) > MAX_PNS: self.ok = False utils.ABT(u"ERROR: P/N 数量超过 %d" % MAX_PNS) if len(tpi_pns) != len(ex_pns): self.ok = False utils.ABT(u"ERROR: 进出口 P/N 不一致") #数目不等 for pn in tpi_pns: in_price = tpi_info.get_unit_price(pn) ex_price = ex_info.get_unit_price(pn) in_qty = tpi_info.get_qty(pn) ex_qty = ex_info.get_qty(pn) if ex_price is None: #or in_qty != ex_qty self.ok = False self.data = {} #clear utils.ABT(u"ERROR: 进出口 P/N 不一致") break if in_qty != ex_qty: utils.ABT(u"ERROR: 进出口 QTY 不一致") #modify it here if in_price >= ex_price: self.data[pn] = {self.PRICE: in_price, self.QTY: in_qty} else: #ex_price > in_price self.data[pn] = { self.PRICE: round(ex_price * 1.01, 2), self.QTY: ex_qty } #TODO: precisious, two decimal
def process_infodb(self, infodb, **kwargs): for pn in self.data.keys(): model = infodb.get_model(pn) code = infodb.get_code(pn) desc = infodb.get_desc(pn) if model is None or code is None or desc is None: self.ok = False utils.ABT(u"ERROR: 在\"规范申报数据库\"中没有找到 P/N: %s" % pn) #return False self.data[pn][self.MODEL] = model self.data[pn][self.CODE] = code self.data[pn][self.DESC] = desc return True
def _process(self,dir): files = os.listdir(dir) #print files for fl in files: #print fl if os.path.isfile(dir+fl) == False: #self.logger.info("illegal file %s" % (dir+fl)) continue #filename = #print filename if fl.split('.')[-1] != "xlsx" and fl.split('.')[-1] != "xls": self.logger.warn(u"PAC 目录中包含非 Excel 文件: %s [已忽略]" % (fl)) continue #print fl self.pac_list.append(PAC(dir+fl,fl.split(".")[0].split("_")[1])) if len(self.pac_list) == 0: utils.ABT(u"ERROR: PAC 文件缺失")