Exemplo n.º 1
0
def staff_log(self, operator_id, station_id, type, staff_name, modify_content=None):
    """
    为员工模块的数据操作记录日志
    :param self: 任务本身
    :param operator_id: 操作人id
    :param station_id: 中转站id
    :param type: 操作类型,1:添加,2.删除,3.编辑
    :param staff_name: 操作对象名称
    :param modify_content: 编辑内容
    :return:
    """

    session = DBSession()
    if type == 1:
        detail = "添加员工({0})".format(staff_name)
    elif type == 2:
        detail = "删除员工({0})".format(staff_name)
    elif type == 3:
        detail = "{0}".format(modify_content)
    else:
        return "参数有误"
    log = models.OperationLog(
        log_type=1,  # 1:员工 2:供货商
        operation_object=staff_name,
        detail=detail,
        creator_id=operator_id,  # 创建人 ID
        station_id=station_id  # 中转站 ID
    )
    session.add(log)
    session.commit()
    session.close()
    return "success"
Exemplo n.º 2
0
def generating_acronym():

    session = DBSession()

    firm_list = session.query(models.Firm)\
                       .filter(models.Firm.status == 0)\
                       .all()
    goods_list = session.query(models.Goods)\
                        .filter(models.Goods.status == 0)\
                        .all()
    for firm in firm_list:
        firm.name = firm.name
    for goods in goods_list:
        goods.name = goods.name

    session.commit()
    session.close()
    return "success"
Exemplo n.º 3
0
def check_msg_token(phone, code):
	s = DBSession()
	try:
		q = s.query(_VerifyCode).filter_by(phone=phone).one()
	except:
		return False
	#print("[验证短信]验证码验证:",q.code,code,q.count,q.wx_id)

	# t = (datetime.datetime.now() - q.create_time)
	# if t.days == 0 and t.seconds >= 18000:
	if q.count  != 1:
		return False

	if q.code == code:
		q.count = 0     # make the code useless
		s.commit()
		s.close()
		return True
	return False
Exemplo n.º 4
0
def update_code(phone,code):
	s = DBSession()
	try:
		print("[VerifyMsg]VerifyCode",code,"have sent to phone:",phone)
		q = s.query(_VerifyCode).filter(_VerifyCode.phone == phone).one()
	except:
		q = None
	if q is not None:
		q.code = code
		q.create_time = datetime.datetime.now()
		q.count = 1
		# q.phone = phone
	else:
		v = _VerifyCode()
		v.phone = phone
		v.code = code
		v.count = 1          # when count = 1,code is usefull
		s.add(v)
	s.commit()
	s.close()
	return True
Exemplo n.º 5
0
def purchasing_dynamics(self, record_type, purchase_goods_dict):
    """
    给采购小程序记录采购动态
    """

    record_type = record_type  # 记录类型
    goods_id = purchase_goods_dict["goods_id"]  # 商品 ID
    purchaser_id = purchase_goods_dict["purchaser_id"]  # 采购员 ID,不安排采购时为空
    creator_id = purchase_goods_dict["creator_id"]  # 操作用户 ID

    goods_name = purchase_goods_dict["goods_name"]  # 商品名称
    last_goods_name = purchase_goods_dict["last_goods_name"]  # 上次的商品名称
    last_goods_name = last_goods_name if last_goods_name else goods_name

    actual_amount = check_int(purchase_goods_dict["actual_amount"] * 100)  # 实际采购件数
    last_actual_amount = purchase_goods_dict["last_actual_amount"]  # 上次的采购件数
    last_actual_amount = last_actual_amount if last_actual_amount else actual_amount

    actual_weight = check_int(purchase_goods_dict["actual_weight"] * 100)  # 实际采购重量
    last_actual_weight = purchase_goods_dict["last_actual_weight"]  # 上次的采购重量
    last_actual_weight = last_actual_weight if last_actual_weight else actual_weight

    actual_unit = purchase_goods_dict["actual_unit"]  # 实际采购单位 0: 件  1: 斤

    price = check_int(purchase_goods_dict["price"] * 100)  # 采购单价
    last_price = purchase_goods_dict["last_price"]  # 上次的采购单价
    last_price = last_price if last_price else price

    subtotal = check_int(purchase_goods_dict["subtotal"] * 100)  # 小计
    last_subtotal = purchase_goods_dict["last_subtotal"]  # 上次的采购小计
    last_subtotal = last_subtotal if last_subtotal else subtotal

    firm_id = purchase_goods_dict["firm_id"]  # 供货商id
    last_firm_id = purchase_goods_dict["last_firm_id"]  # 上次的供货商id
    last_firm_id = last_firm_id if last_firm_id else firm_id

    payment = purchase_goods_dict["payment"]  # 支付方式 0: 现金 1: 银行卡 2: 微信 3: 支付宝 4: 赊账 5: 其他
    is_purchase = purchase_goods_dict["is_purchase"]  # 0: 正常 1: 不采了
    tag = purchase_goods_dict["tag"]  # 商品标签 0: 正常 1:采购员手动添加
    remarks = purchase_goods_dict["remarks"]  # 采购备注
    purchase_order_goods_id = purchase_goods_dict["id"]  # 采购单商品 ID
    purchase_order_id = purchase_goods_dict["purchase_order_id"]  # 采购单 ID
    wish_order_goods_id = purchase_goods_dict["wish_order_goods_id"]  # 意向单商品 ID, 手动添加的采购商品,没有对应的意向单id

    session = DBSession()
    new_dynamic = models.PurchasingDynamics(
        record_type=record_type,
        goods_id=goods_id,
        purchaser_id=purchaser_id,
        creator_id=creator_id,
        goods_name=goods_name,
        last_goods_name=last_goods_name,
        actual_amount=actual_amount,
        last_actual_amount=last_actual_amount,
        actual_weight=actual_weight,
        last_actual_weight=last_actual_weight,
        actual_unit=actual_unit,
        price=price,
        last_price=last_price,
        subtotal=subtotal,
        last_subtotal=last_subtotal,
        firm_id=firm_id,
        last_firm_id=last_firm_id,
        payment=payment,
        is_purchase=is_purchase,
        tag=tag,
        remarks=remarks,
        purchase_order_goods_id=purchase_order_goods_id,
        purchase_order_id=purchase_order_id,
        wish_order_goods_id=wish_order_goods_id
    )
    session.add(new_dynamic)
    session.commit()
    session.close()
    return "success"
Exemplo n.º 6
0
            raise Exception('{} 的库存量 {} 不是纯数字,手动改改'.format(name, storage))
        if demand_amount and not isinstance(
                demand_amount, float) and not isinstance(demand_amount, int):
            raise Exception('{} 的订货量 {} 不是纯数字,手动改改'.format(
                name, demand_amount))

        # 用名字把商品查出来
        goods = session.query(models.Goods) \
            .filter(models.Goods.name == name,
                    models.Goods.station_id == station_id) \
            .first()
        if not goods:
            raise Exception('没找到 {},先手动建好加到意向单里吧'.format(name))

        wish_goods = wish_goods_dict.get(goods.id)
        if not wish_goods:
            raise Exception('意向单里没有 {},先去手动加到意向单里'.format(name))

        # 拿本行数据建一个订货单商品
        demand_goods = models.DemandOrderGoods(
            current_storage=round(storage * 100) if storage else 0,
            demand_amount=round(demand_amount * 100) if demand_amount else 0,
            goods_id=goods.id,
            demand_order_id=demand_order.id,
            wish_order_goods_id=wish_goods.id,
        )
        session.add(demand_goods)
        session.flush()

    session.commit()