1. 月盘
1.1 月末负库存清零任务:
任务地址:https://store.lelecha.com/chronos.html
name:月盘负库存清零
topic: supply.stocktake.negative_stocktake_zero.init
和客户沟通过,暂时配置为每个月1号3:30执行,对应utc时间:就是每个月末最后一天的19:30执行
1.2 修改报废时间和盘点时间
由于报废日期和盘点日期是自然日,而库存切片是4点~4点,这样会导致报表和库存切片数据不一致,因此,就要求在凌晨0点~4点之间盘点或者报废的单子,应该算在前一天。这个需求已经实现并发布到生产,上个月的月结报废日期和盘点日期应该是对的,客户并没有让改。但为防止意外,附上对应的脚本
import pymysql import xlrd
from util.read_file import read_excel
def update_adjust(created_at, adjust_date, codes):
# 更新收货单状态db = pymysql.connect(host="pc-uf649stob1f3o4si8.rwlb.rds.aliyuncs.com",port=3306,user="lelecha_prod",passwd="EdCD4u69etNJHb7z",db="lelecha_boh_supply")# 通过 cursor() 创建游标对象cur = db.cursor()# 更新报废单时间update_sql = """UPDATE supply_adjust_detail SET created_at = '{created_at}', adjust_date = '{adjust_date}' WHERE `code` in ({codes})""".\format(created_at=created_at, adjust_date=adjust_date, codes=codes)try:# 使用 execute() 执行sqlcur.execute(update_sql)# 提交事务db.commit()except Exception as e:print("更新失败,error = {}".format(e))# 回滚所有的更改db.rollback()finally:print("更新成功")print("受影响行数:{}".format(cur.rowcount))# 关闭游标cur.close()# 关闭数据库连接db.close()
默认读出第一列
def read_excel(path=None, file_name=None): if not path: path = os.getcwd() + “/files/excel/“ rows = []
# 打开文件workbook = xlrd.open_workbook(path + file_name)# 获取所有sheetsheets = workbook.sheet_names()for sheet in sheets:# 根据sheet索引或者名称获取sheet内容sheet = workbook.sheet_by_name(sheet)rows = sheet.nrows()cols = sheet.col_values(0) # 获取第1列内容for col in cols[1:]:col_str = str(int(col))rows.append(col_str)print("rows = {}".format(rows))return rows
if name == ‘main‘:
# 读取指定列# path = os.getcwd() + "/"file_name = "报废单.xlsx"rows = read_excel(file_name=file_name)codes= ",".join(rows)# 更新至 2021-11-30# created_at = "2021-11-30 15:50:00"# adjust_date = "2021-11-30 15:50:00"# 更新至 2021-12-31created_at = "2021-12-31 15:50:00"adjust_date = "2021-12-31 15:50:00"update_adjust(created_at=created_at, adjust_date=adjust_date, codes=codes)
2. 修改盘点单日期```python# 更新盘点单import osimport pymysqlimport xlrdfrom db.lelecha_boh_prod import get_dbfrom util.read_file import read_exceldef update_stocktake(target_date, codes):# 更新收货单状态db = pymysql.connect(host="pc-uf649stob1f3o4si8.rwlb.rds.aliyuncs.com",port=3306,user="lelecha_prod",passwd="EdCD4u69etNJHb7z",db="lelecha_boh_supply")# 通过 cursor() 创建游标对象cur = db.cursor()# 更新报废单时间update_sql = """UPDATE supply_st_doc_details SET target_date = '{target_date}' WHERE `code` in ({codes})""".format(target_date=target_date, codes=codes)try:# 使用 execute() 执行sqlcur.execute(update_sql)# 提交事务db.commit()except Exception as e:print("更新失败,error = {}".format(e))# 回滚所有的更改db.rollback()finally:print("更新成功")print("受影响行数:{}".format(cur.rowcount))# 关闭游标cur.close()# 关闭数据库连接db.close()# 默认读出第一列def read_excel(path=None, file_name=None):if not path:path = os.getcwd() + "/files/excel/"rows = []# 打开文件workbook = xlrd.open_workbook(path + file_name)# 获取所有sheetsheets = workbook.sheet_names()for sheet in sheets:# 根据sheet索引或者名称获取sheet内容sheet = workbook.sheet_by_name(sheet)rows = sheet.nrows()cols = sheet.col_values(0) # 获取第1列内容for col in cols[1:]:col_str = str(int(col))rows.append(col_str)print("rows = {}".format(rows))return rowsif __name__ == '__main__':# 读取指定列# path = os.getcwd() + "/"file_name = "盘点单.xlsx"rows = read_excel(file_name=file_name)codes= ",".join(rows)# 更新至 2021-12-31target_date = "2021-12-31 15:50:00"update_stocktake(target_date=target_date, codes=codes)
2. 变更收货单状态
之前客户有遇到过明明已经收货,但收货单仍旧显示 未到店,就需要手动 更改 单据的状态
import pymysql, xlrd, osclass UpdateReceiptReceive(object):# 更新门店收货单状态:未到店 ———> 待收货def __init__(self):# 初始化passdef run(self):# 主程序# 读取要更新的收货单code_listpath = os.getcwd() + "/"file_name = "未到店.xlsx"code_list = self.get_receive_codes(path=path, file_name=file_name)codes = ",".join(code_list)# 更新收货单状态self.update_receive(codes=codes)def update_receive(self, codes):# 更新收货单状态print("codes = {}".format(codes))# 建立数据库连接db = pymysql.connect(host="pc-uf649stob1f3o4si8.rwlb.rds.aliyuncs.com",port=3306,user="lelecha_prod",passwd="EdCD4u69etNJHb7z",db="lelecha_boh_receipt")# 通过 cursor() 创建游标对象cur = db.cursor()# 未到店 ———> 待收货update_sql = """UPDATE receipt_receive SET `status` = 'INITED' WHERE `status` = 'SUSPENDED' AND `code` in ({})""".format(codes)# 待收货 ---> 已收货# update_sql = """UPDATE receipt_receive SET `status` = 'SUCCESS' WHERE `status` = 'INITED' AND `code` in ({})""".format(codes)try:# 使用 execute() 执行sqlcur.execute(update_sql)# 提交事务db.commit()except Exception as e:print("更新失败,error = {}".format(e))# 回滚所有的更改db.rollback()finally:print("更新成功")print("受影响行数:{}".format(cur.rowcount))# 关闭游标cur.close()# 关闭数据库连接db.close()def get_receive_codes(self, path, file_name):# 获取收货单编码列表code_list = list()# 打开文件workbook = xlrd.open_workbook(path + file_name)# 获取所有sheetsheets = workbook.sheet_names()for sheet_name in sheets:# 根据sheet索引或者名称获取sheet内容sheet = workbook.sheet_by_name(sheet_name)cols = sheet.col_values(1) # 获取第2列内容for col in cols[1:]:col_str = str(int(col))code_list.append(col_str)return code_listif __name__ == '__main__':URR = UpdateReceiptReceive()URR.run()
