Beispiel #1
0
    def stork_repeat(self):
        """
        重新入库
        """
        data = parameter_required(
            ("repeat_warehousing_name", "repeat_warehousing_card_no",
             "procedure_id"))
        procedure_instance = an_procedure.query.filter(
            an_procedure.id == data.get("procedure_id")).first()
        procedure_dict = {}
        procedure_dict["repeat_warehousing_name"] = data.get(
            "repeat_warehousing_name")
        procedure_dict["repeat_warehousing_card_no"] = data.get(
            "repeat_warehousing_card_no")
        procedure_dict["repeat_warehousing_time"] = datetime.datetime.now()
        procedure_dict["preservation"] = "repeat"
        procedure_dict["repeat_warehousing_inputer_id"] = getattr(
            request, "user").id
        procedure_dict["repeat_warehousing_inputer_name"] = getattr(
            request, "user").username

        with db.auto_commit():
            procedure_instance.update(procedure_dict, null="not")
            db.session.add(procedure_instance)

        return Success(message="重新入库成功")
Beispiel #2
0
 def get_master_number(self):
     """
     模糊搜索单号
     """
     args = parameter_required(("master_number", ))
     procedure = an_procedure.query.filter(an_procedure.master_number.like("%{0}%".format(args.get("master_number"))))\
         .all_with_page()
     master_dict = []
     for row in procedure:
         master_dict.append(row.master_number)
     return Success(data=master_dict)
Beispiel #3
0
    def get_mechandis_remark(self):
        """
        获取盘库备注
        """
        args = parameter_required(("token", "master_id"))
        time_zones_dict = self._get_time_zones()
        filter_args = [
            an_master_number_remark.createtime > time_zones_dict["time_start"],
            an_master_number_remark.createtime < time_zones_dict["time_end"],
            an_master_number_remark.master_number_id == args.get("master_id")
        ]
        mechandis_remark = an_master_number_remark.query.filter(*filter_args)\
            .order_by(an_master_number_remark.createtime.desc()).first()
        if not mechandis_remark:
            mechandis_remark = {"message": ""}

        return Success(data=mechandis_remark)
Beispiel #4
0
    def get_mechandis_history(self):
        """
        获取盘库历史详情
        """
        args = parameter_required(('main_id', 'token'))

        # 排序
        part_inventory = an_mechandise_inventory_part.query.filter(
            an_mechandise_inventory_part.main_id == args.get("main_id"))\
            .order_by(an_mechandise_inventory_part.master_number_cut.desc()).all_with_page()

        for row in part_inventory:
            procedure = an_procedure.query.filter(
                an_procedure.id == row.master_id).first()
            row.fill("inputer_name", procedure.inputer_name)
            row.fill("create_time", procedure.create_time)

        return Success(data=part_inventory)
Beispiel #5
0
    def make_mechandis_remark(self):
        """
        提交盘库备注
        """
        data = parameter_required(("message", "master_id"))
        user_id = getattr(request, "user").id
        user = an_user.query.filter(
            an_user.user_id == user_id).first_("未找到该用户")
        with db.auto_commit():
            an_remark_instance = an_master_number_remark.create({
                "id":
                str(uuid.uuid1()),
                "master_number_id":
                data.get("master_id"),
                "message":
                data.get("message"),
                "createtime":
                datetime.datetime.now(),
                "user_id":
                user_id
            })
            db.session.add(an_remark_instance)

        return Success(message="备注成功")
Beispiel #6
0
    def get(self):
        """
        获取详情
        1.基于id(获取详情)
        2.基于master_number(创建一条数据后,返回详情)
        """
        args = parameter_required(("procedure_type", ))
        if args.get("procedure_type") not in ["in", "out"]:
            return ParamsError("参数类型错误")
        if args.get("id"):
            procedure = an_procedure.query.filter(an_procedure.procedure_type == args.get("procedure_type"),
                                                  an_procedure.id == args.get("id"))\
                .first_("未找到该单据")
            if procedure.freight_type == "PASSENGER AND CARGO AIRCRAFT":
                procedure.fill("freight_type_ch", "客货均可")
            elif procedure.freight_type == "CARGO AIRCRAFT ONLY":
                procedure.fill("freight_type_ch", "仅限货机")
            else:
                procedure.fill("freight_type_ch", None)
            if procedure.type_of_shipping == "NON-RADIOACTIVE":
                procedure.fill("type_of_shipping_ch", "非放射性")
            elif procedure.type_of_shipping == "RADIOACTIVE":
                procedure.fill("type_of_shipping_ch", "放射性")
            else:
                procedure.fill("type_of_shipping_ch", None)
            history_list = self._get_history_list(procedure)
            procedure_picture_list = an_procedure_picture.query.filter(
                an_procedure_picture.procedure_id == args.get("id")).all()
            procedure.fill("history_list", history_list)
            procedure.fill("picture_list", procedure_picture_list)
            return Success(data=procedure)
        elif args.get("master_number"):
            procedure_dict = {}
            procedure_dict["procedure_type"] = args.get("procedure_type")
            procedure_dict["master_number"] = args.get("master_number")
            procedure_dict["inputer_id"] = getattr(request, "user").id
            user_dict = an_user.query.filter(an_user.user_id == getattr(
                request, "user").id).first_("未找到该用户")
            procedure_dict["inputer_name"] = user_dict.user_truename
            procedure_dict["inputer_card_no"] = user_dict.cardno
            procedure_dict["create_time"] = datetime.datetime.now()
            procedure_dict["preservation"] = "wait"
            id = str(uuid.uuid1())
            procedure_dict["id"] = id
            procedure_dict["master_number_cut"] = str(
                args.get("master_number"))[-4:] or ""
            main_port = t_bgs_main_single_number.query.filter(
                t_bgs_main_single_number.master_number == args.get(
                    "master_number")).first()
            if main_port:
                procedure_dict[
                    "port_of_departure"] = main_port.port_of_departure
                procedure_dict["destination_port"] = main_port.destination_port
                # 2020/12/1 增加字段
                procedure_dict["type_of_shipping"] = main_port.type_of_shipping
                procedure_dict["freight_type"] = main_port.freight_type
                # 数量用来填写
                procedure_dict["product_number"] = None
            with db.auto_commit():
                procedure_instance = an_procedure.create(procedure_dict)
                db.session.add(procedure_instance)

            procedure = an_procedure.query.filter(
                an_procedure.id == id).first()
            procedure.fill("picture_list", [])
            history_list = self._get_history_list(procedure)
            procedure.fill("history_list", history_list)
            return Success(data=procedure)
        else:
            return ParamsError()
Beispiel #7
0
    def stork_in(self):
        """
        入库
        """
        data = parameter_required(
            ("handover_name", "handover_card_no", "area_id", "storing_id",
             "product_number", "weight", "procedure_id"))
        procedure_instance = an_procedure.query.filter(
            an_procedure.id == data.get("procedure_id")).first()
        procedure_dict = {}
        procedure_dict["handover_name"] = data.get("handover_name")
        procedure_dict["handover_card_no"] = data.get("handover_card_no")
        procedure_dict["handover_time"] = datetime.datetime.now()
        procedure_dict["handover_inputer_id"] = getattr(request, "user").id
        procedure_dict["handover_inputer_name"] = getattr(request,
                                                          "user").username

        if data.get("preservation_id"):
            preservation = an_preservation_type.query.filter(an_preservation_type.id == data.get("preservation_id")) \
                .first_("未找到该类别")
            storing_id = preservation.storing_id
            if storing_id != data.get("storing_id"):
                return ParamsError("仓位中无此类别,请先选择仓位再选择类别")
            storing = an_storing_location.query.filter(
                an_storing_location.id == storing_id).first_("未找到该仓位")
            area_id = storing.area_id
            if area_id != data.get("area_id"):
                return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            area = an_area.query.filter(
                an_area.id == data.get("area_id")).first_("未找到该区域")

            procedure_dict[
                "preservation_type"] = preservation.preservation_type_name
        elif data.get("board_no"):
            storing = an_storing_location.query.filter(an_storing_location.id == data.get("storing_id")) \
                .first_("未找到该仓位")
            if storing.storing_location_name not in [
                    "大货区", "锂电池暂存区", "ETV区", "Stacker区"
            ]:
                return ParamsError("需要选择特殊仓位")
            area_id = storing.area_id
            if area_id != data.get("area_id"):
                return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            area = an_area.query.filter(
                an_area.id == data.get("area_id")).first_("未找到该区域")

            procedure_dict["board_no"] = data.get("board_no")
        else:
            return ParamsError("请输入类别或者板号")

        procedure_dict["preservation_area"] = area.area_name
        procedure_dict["storing_location"] = storing.storing_location_name
        procedure_dict["weight"] = data.get("weight")
        procedure_dict["product_number"] = data.get("product_number")
        if data.get("remarks"):
            procedure_dict["remarks"] = data.get("remarks")

        procedure_dict["preservation"] = "in"
        # TODO 图片上传
        if data.get("picture_list"):
            for row in data.get("picture_list"):
                url_instance = an_procedure_picture.query.filter(an_procedure_picture.file_url == row)\
                    .first_("该图片未上传成功, 请重新上传")
                with db.auto_commit():
                    url_instance.update(
                        {"procedure_id": data.get("procedure_id")}, null="not")
                    db.session.add(url_instance)

        with db.auto_commit():
            procedure_instance.update(procedure_dict, null="not")
            db.session.add(procedure_instance)

        return Success(message="入库成功")
Beispiel #8
0
    def list(self):
        """
        获取列表
        """
        args = parameter_required(("procedure_type", ))
        filter_args = []
        filter_args.append(
            an_procedure.procedure_type == args.get("procedure_type"))
        if args.get("preservation_id"):
            preservation = an_preservation_type.query.filter(an_preservation_type.id == args.get("preservation_id"))\
                .first_("未找到该类别")
            storing_id = preservation.storing_id
            if args.get("storing_id"):
                if storing_id != args.get("storing_id"):
                    return ParamsError("仓位中无此类别,请先选择仓位再选择类别")
            storing = an_storing_location.query.filter(
                an_storing_location.id == storing_id).first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(an_procedure.preservation_type ==
                               preservation.preservation_type_name)
        if args.get("storing_id"):
            storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                .first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(
                an_procedure.storing_location == storing.storing_location_name)
        if args.get("area_id"):
            area = an_area.query.filter(
                an_area.id == args.get("area_id")).first_("未找到该区域")
            filter_args.append(
                an_procedure.preservation_area == area.area_name)
        if args.get("board_no"):
            if args.get("storing_id"):
                storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                    .first_("未找到该仓位")
                if storing.storing_location_name not in [
                        "大货区", "锂电池暂存区", "ETV区", "Stacker区"
                ]:
                    return ParamsError("需要选择特殊仓位")
                area_id = storing.area_id
                if args.get("area_id"):
                    if area_id != args.get("area_id"):
                        return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
                filter_args.append(
                    an_procedure.board_no == args.get("board_no"))
            else:
                return ParamsError("需要选择特殊仓位")
        if args.get("master_number"):
            filter_args.append(
                an_procedure.master_number.like("%{0}%".format(
                    args.get("master_number"))))

        # TODO 2021/3/15 新增需求
        if args.get("preservation"):
            filter_args.append(
                an_procedure.preservation == args.get("preservation"))

        page_size = args.get("page_size") or 15
        page_num = args.get("page_num") or 1

        procedure_list = an_procedure.query.filter(*filter_args).order_by(
            an_procedure.create_time.desc()).all_with_page()

        i = 1
        for procedure in procedure_list:
            if not procedure.product_number:
                procedure.product_number = 0
            procedure.fill("procedure_no",
                           int(page_size) * (int(page_num) - 1) + i)
            i = i + 1

        return Success(data=procedure_list)
Beispiel #9
0
    def get_mechandis_list(self):
        """
        获取可盘库的列表
        """
        args = parameter_required(("token", ))
        page_size = int(args.get("page_size")) or 15
        page_num = int(args.get("page_num")) or 1
        time_zones_dict = self._get_time_zones()
        mechandise_inventory_part = an_mechandise_inventory_part.query.filter(
            an_mechandise_inventory_part.createtime >
            time_zones_dict["time_start"],
            an_mechandise_inventory_part.createtime <
            time_zones_dict["time_end"]).all()

        master_list = []
        for row in mechandise_inventory_part:
            master_list.append(row.master_id)

        filter_args = [
            an_procedure.id.notin_(master_list),
            an_procedure.preservation.in_(["repeat", "in"])
        ]

        if args.get("preservation_id"):
            preservation = an_preservation_type.query.filter(an_preservation_type.id == args.get("preservation_id"))\
                .first_("未找到该类别")
            storing_id = preservation.storing_id
            if args.get("storing_id"):
                if storing_id != args.get("storing_id"):
                    return ParamsError("仓位中无此类别,请先选择仓位再选择类别")
            storing = an_storing_location.query.filter(
                an_storing_location.id == storing_id).first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(an_procedure.preservation_type ==
                               preservation.preservation_type_name)
        if args.get("storing_id"):
            storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                .first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(
                an_procedure.storing_location == storing.storing_location_name)
        if args.get("area_id"):
            area = an_area.query.filter(
                an_area.id == args.get("area_id")).first_("未找到该区域")
            filter_args.append(
                an_procedure.preservation_area == area.area_name)
        if args.get("board_no"):
            if args.get("storing_id"):
                storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                    .first_("未找到该仓位")
                if storing.storing_location_name not in [
                        "大货区", "锂电池暂存区", "ETV区", "Stacker区"
                ]:
                    return ParamsError("需要选择特殊仓位")
                area_id = storing.area_id
                if args.get("area_id"):
                    if area_id != args.get("area_id"):
                        return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
                filter_args.append(
                    an_procedure.board_no == args.get("board_no"))
            else:
                return ParamsError("需要选择特殊仓位")
        if args.get("master_number"):
            filter_args.append(
                an_procedure.master_number.like("%{0}%".format(
                    args.get("master_number"))))

        # 20210518需求变更,根据危险品类别排序,再根据单号后四位排序
        master_list = an_procedure.query.filter(*filter_args)\
            .order_by(an_procedure.create_time.desc(),
                      an_procedure.master_number_cut.asc())\
            .all_with_page()
        port_no = 1 + page_size * (page_num - 1)
        for master_dict in master_list:
            master_dict.fill("port_no", port_no)
            port_no += 1

        return Success(data=master_list)
Beispiel #10
0
    def get_mechandis_history_list(self):
        """
        获取盘库历史列表
        """
        args = parameter_required(("token", ))
        page_size = int(args.get("page_size")) or 15
        page_num = int(args.get("page_num")) or 1
        time_zones_dict = self._get_time_zones()

        filter_args = []

        if args.get("preservation_id"):
            preservation = an_preservation_type.query.filter(an_preservation_type.id == args.get("preservation_id"))\
                .first_("未找到该类别")
            storing_id = preservation.storing_id
            if args.get("storing_id"):
                if storing_id != args.get("storing_id"):
                    return ParamsError("仓位中无此类别,请先选择仓位再选择类别")
            storing = an_storing_location.query.filter(
                an_storing_location.id == storing_id).first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(an_mechandise_inventory_part.preservation_type
                               == preservation.preservation_type_name)
        if args.get("storing_id"):
            storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                .first_("未找到该仓位")
            area_id = storing.area_id
            if args.get("area_id"):
                if area_id != args.get("area_id"):
                    return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
            filter_args.append(an_mechandise_inventory_part.storing_location ==
                               storing.storing_location_name)
        if args.get("area_id"):
            area = an_area.query.filter(
                an_area.id == args.get("area_id")).first_("未找到该区域")
            filter_args.append(an_mechandise_inventory_part.preservation_area
                               == area.area_name)
        if args.get("board_no"):
            if args.get("storing_id"):
                storing = an_storing_location.query.filter(an_storing_location.id == args.get("storing_id"))\
                    .first_("未找到该仓位")
                if storing.storing_location_name not in [
                        "大货区", "锂电池暂存区", "ETV区", "Stacker区"
                ]:
                    return ParamsError("需要选择特殊仓位")
                area_id = storing.area_id
                if args.get("area_id"):
                    if area_id != args.get("area_id"):
                        return ParamsError("该区域中无此仓位,请先选择区域再选择仓位")
                filter_args.append(an_mechandise_inventory_part.board_no ==
                                   args.get("board_no"))
            else:
                return ParamsError("需要选择特殊仓位")
        if args.get("master_number"):
            filter_args.append(
                an_mechandise_inventory_part.master_number.like("%{0}%".format(
                    args.get("master_number"))))

        if args.get("start_time"):
            filter_args.append(an_mechandise_inventory_part.createtime >
                               args.get("start_time"))

        if args.get("end_time"):
            filter_args.append(
                an_mechandise_inventory_part.createtime < args.get("end_time"))

        master_id_list = []
        mechandise_inventory_part = an_mechandise_inventory_part.query.filter(*filter_args)\
            .order_by(an_mechandise_inventory_part.createtime.desc()).all()
        for mechandise in mechandise_inventory_part:
            if mechandise["main_id"] not in master_id_list:
                master_id_list.append(mechandise["main_id"])

        master_id_page = master_id_list[(page_num - 1) * page_size:page_num *
                                        page_size]

        total_count = len(master_id_page)
        if total_count % page_size == 0:
            total_page = int(total_count / page_size)
        else:
            total_page = int(total_count / page_size) + 1

        port_no = 1 + page_size * (page_num - 1)
        merchandise_inventory_main = []
        for master_id in master_id_page:
            merchandise_inventory_main_dict = an_merchandise_inventory_main.query.filter(
                an_merchandise_inventory_main.id == master_id).first()
            if merchandise_inventory_main_dict:
                merchandise_inventory_main_dict.fill("port_no", port_no)
                merchandise_inventory_main.append(
                    merchandise_inventory_main_dict)
                port_no += 1

        return {
            "status": 200,
            "message": "获取成功",
            "data": merchandise_inventory_main,
            "total_page": total_page,
            "total_count": total_count
        }