Exemple #1
0
def login():
    if request.method == "GET":
        if current_user.is_anonymous:
            return render_template("auth/login.html", titlename=u'登录')
        return redirect("/")
    else:
        class LoginForm(Form):
            username = TextField()
            password = PasswordField()
            next_url = HiddenField()

        form = LoginForm(request.form)
        if form.validate():
            username = form.username.data
            password = form.password.data
            try:
                import lite_mms.apis as apis

                user = apis.auth.authenticate(username, password)
            except AuthenticateFailure:
                return render_template("auth/login.html", error=_(u"用户名或者密码错误"), titlename=u"请登录"), 403
            if not user.enabled:
                return render_template("auth/login.html", error=_(u"该账户已禁用, 请使用其它账户"), titlename=u"请登录"), 403
            if not login_user(user):
                return render_template("auth/login.html", error=_(u"登陆失败"), titlename=u"请登录"), 403

            identity_changed.send(current_app._get_current_object(), identity=Identity(user.id))
            return redirect(form.next_url.data or "/")
        else:
            return render_template("auth/login.html", error=_(u"请输入用户名及密码"), titlename=u"请登录"), 403
Exemple #2
0
def _trans_order_type(order_type):
    if order_type == constants.STANDARD_ORDER_TYPE:
        return _(u"计重")
    elif order_type == constants.EXTRA_ORDER_TYPE:
        return _(u"计件")
    else:
        return _(u"未知")
Exemple #3
0
    def new_sub_order(cls, **kwargs):
        """新建计件类型的子订单。
        """
        order = get_order(kwargs["order_id"])
        if not order:
            raise ValueError(_(u'订单%d不存在') % kwargs["order_id"])

        try:
            harbor = models.Harbor.query.filter(
                models.Harbor.name == kwargs["harbor_name"]).one()
        except NoResultFound:
            raise ValueError(_(u'装卸点%(harbor)s不存在') % kwargs["harbor_name"])

        try:
            product = models.Product.query.filter(
                models.Product.id == kwargs["product_id"]).one()
        except NoResultFound:
            raise ValueError(_(u'产品%(product_id)不存在') % kwargs["product_id"])

        sb = models.SubOrder(harbor=harbor,
                             product=product,
                             spec=kwargs["spec"],
                             type=kwargs["type"],
                             order=order,
                             urgent=kwargs["urgent"],
                             returned=kwargs["returned"],
                             tech_req=kwargs["tech_req"],
                             quantity=kwargs["quantity"],
                             unit=kwargs["unit"],
                             due_time=kwargs["due_time"],
                             order_type=constants.EXTRA_ORDER_TYPE,
                             weight=kwargs["weight"])

        return SubOrderWrapper(do_commit(sb))
Exemple #4
0
    def new_sub_order(cls, **kwargs):
        """新建计件类型的子订单。
        """
        order = get_order(kwargs["order_id"])
        if not order:
            raise ValueError(_(u'订单%d不存在') % kwargs["order_id"])

        try:
            harbor = models.Harbor.query.filter(
                models.Harbor.name == kwargs["harbor_name"]).one()
        except NoResultFound:
            raise ValueError(_(u'装卸点%(harbor)s不存在') % kwargs["harbor_name"])

        try:
            product = models.Product.query.filter(
                models.Product.id == kwargs["product_id"]).one()
        except NoResultFound:
            raise ValueError(_(u'产品%(product_id)不存在') % kwargs["product_id"])

        sb = models.SubOrder(harbor=harbor,
                             product=product,
                             spec=kwargs["spec"],
                             type=kwargs["type"],
                             order=order,
                             urgent=kwargs["urgent"],
                             returned=kwargs["returned"],
                             tech_req=kwargs["tech_req"],
                             quantity=kwargs["quantity"],
                             unit=kwargs["unit"],
                             due_time=kwargs["due_time"],
                             order_type=constants.EXTRA_ORDER_TYPE,
                             weight=kwargs["weight"])

        return SubOrderWrapper(do_commit(sb))
Exemple #5
0
def _trans_order_type(order_type):
    if order_type == constants.STANDARD_ORDER_TYPE:
        return _(u"计重")
    elif order_type == constants.EXTRA_ORDER_TYPE:
        return _(u"计件")
    else:
        return _(u"未知")
Exemple #6
0
def delivery_session():
    """
    get delivery session from database
    """
    _id = request.args.get("id", type=int)
    if not _id:
        return _(u"需要id字段"), 403
    import lite_mms.apis as apis

    ds = apis.delivery.get_delivery_session(_id)
    if not ds:
        return _(u"没有如下发货会话") + str(_id), 404
    ret = dict(id=ds.id, plate=ds.plate)
    # store_bills是个两层结构,第一层是order,第二层主键是suborder
    store_bills = {}
    for sb in ds.store_bill_list:
        if not sb.delivery_task:  # not delivered yet
            sub_order_2_store_bill = store_bills.setdefault(
                str(sb.sub_order.order.customer_order_number), {})
            sb_list = sub_order_2_store_bill.setdefault(sb.sub_order.id, [])
            sb_list.append(
                dict(id=sb.id,
                     harbor=sb.harbor.name,
                     product_name=sb.product_name,
                     spec=sb.sub_order.spec,
                     type=sb.sub_order.type,
                     customer_name=sb.customer.name,
                     pic_url=sb.pic_url,
                     unit=sb.sub_order.unit,
                     weight=sb.weight))
    ret.update(store_bills=store_bills)
    return json.dumps(ret)
Exemple #7
0
def login():
    if request.method == "GET":
        if current_user.is_anonymous():
            return render_template("auth/login.html", titlename=u'登录')
        return redirect("/")
    else:
        class LoginForm(Form):
            username = TextField()
            password = PasswordField()
            next_url = HiddenField()

        form = LoginForm(request.form)
        if form.validate():
            username = form.username.data
            password = form.password.data
            try:
                import lite_mms.apis as apis

                user = apis.auth.authenticate(username, password)
            except AuthenticateFailure:
                return render_template("auth/login.html", error=_(u"用户名或者密码错误"), titlename=u"请登录"), 403
            if not user.enabled:
                return render_template("auth/login.html", error=_(u"该账户已禁用, 请使用其它账户"), titlename=u"请登录"), 403
            if not login_user(user):
                return render_template("auth/login.html", error=_(u"登陆失败"), titlename=u"请登录"), 403

            identity_changed.send(current_app._get_current_object(), identity=Identity(user.id))
            return redirect(form.next_url.data or "/")
        else:
            return render_template("auth/login.html", error=_(u"请输入用户名及密码"), titlename=u"请登录"), 403
Exemple #8
0
def customer_list():
    """
    return the customers, params include:
    * delivery_session_id
    """
    delivery_session_id = request.args.get("delivery_session_id", type=int)
    customers = []
    if delivery_session_id is not None:
        import lite_mms.apis as apis

        delivery_session = apis.delivery.get_delivery_session(
            delivery_session_id)
        if not delivery_session.finish_time:
            return _(u"发货会话尚未结束"), 403
        if any(task.weight == 0 for task in delivery_session.delivery_task_list):
            return _(u"请先对所有的发货任务进行称重"), 403

        acked_customer_id_list = set([gr.customer_id for gr in
                                      delivery_session.consignment_list])
        customers = [c for c in delivery_session.customer_list if
                     c.id not in acked_customer_id_list]
        if not customers:
            return _(u"已经对所有的客户生成了发货单"), 403

    return json.dumps([{"id": c.id, "name": c.name} for c in customers])
Exemple #9
0
def customer_list():
    """
    return the customers, params include:
    * unload_session_id
    """
    unload_session_id = request.args.get("unload_session_id", None)
    customers = []
    if unload_session_id:
        unload_session_id = int(unload_session_id)
        from lite_mms import apis

        unload_session = apis.cargo.get_unload_session(unload_session_id)
        if not unload_session.finish_time:
            return _(u"卸货会话尚未结束"), 403
        if any(task.weight == 0 for task in unload_session.task_list):
            return _(u"请先对所有的卸货任务进行称重"), 403
        acked_customer_id_list = set(
            [gr.customer_id for gr in unload_session.goods_receipt_list])
        customers = [
            c for c in unload_session.customer_list
            if c.id not in acked_customer_id_list
        ]
    if not customers:
        return _(u"已经对所有的用户生成了收货单"), 403
    return json.dumps([{"id": c.id, "name": c.name} for c in customers])
 def remove(cls, id_, actor_id):
     """
     remove the quality inspection report on database
     """
     qir = cls.get(id_)
     if not qir:
         raise ValueError(_(u"无此报告单(%s)" % id_))
     if qir.work_command.status != wc_const.STATUS_QUALITY_INSPECTING:
         raise ValueError(_(u"已提交的质检单中的质检报告不能删除"))
     do_commit(qir.model, action="delete")
     return "sucess"
Exemple #11
0
 def remove(cls, id_, actor_id):
     """
     remove the quality inspection report on database
     """
     qir = cls.get(id_)
     if not qir:
         raise ValueError(_(u"无此报告单(%s)" % id_))
     if qir.work_command.status != wc_const.STATUS_QUALITY_INSPECTING:
         raise ValueError(_(u"已提交的质检单中的质检报告不能删除"))
     do_commit(qir.model, action="delete")
     return "sucess"
Exemple #12
0
def consignment_list():
    session_id = request.args.get("delivery_session_id", type=int)
    if session_id is not None:
        import lite_mms.apis as apis

        consignments, totalcnt = apis.delivery.get_consignment_list(session_id)
        if not consignments:
            return _(u"当前没有任何发货单"), 404
        return json.dumps(
            [dict(id=c.id, customer=c.customer.name,
                  consignment_id=c.consignment_id) for c in consignments])
    else:
        return _(u"未选择发货会话"), 403
Exemple #13
0
def order_modify():
    from lite_mms import apis

    order = apis.order.get_order(request.form["order_id"])
    if not order:
        return _(u"不存在订单ID为%s的订单" % request.form["order_id"]), 403
    if any(
            sub_order.work_command_list for sub_order in order.sub_order_list):
        return _(u"该订单已排产,请勿修改"), 500
    try:
        order.update(customer_order_number=request.form["customer_order_number"])
        return _(u"修改成功")
    except ValueError:
        return _(u"修改失败"), 403
Exemple #14
0
def order_modify():
    from lite_mms import apis

    order = apis.order.get_order(request.form["order_id"])
    if not order:
        return _(u"不存在订单ID为%s的订单" % request.form["order_id"]), 403
    if any(sub_order.work_command_list for sub_order in order.sub_order_list):
        return _(u"该订单已排产,请勿修改"), 500
    try:
        order.update(
            customer_order_number=request.form["customer_order_number"])
        return _(u"修改成功")
    except ValueError:
        return _(u"修改失败"), 403
Exemple #15
0
def ajax_sub_order():
    sub_order_id = request.args.get('id', type=int)
    if not sub_order_id:
        return _(u"不存在该订单"), 404
    from lite_mms import apis

    inst = apis.order.get_sub_order(sub_order_id)
    if not inst:
        return "no sub order with id " + str(sub_order_id), 404
    from lite_mms.basemain import nav_bar
    from lite_mms.constants import DEFAULT_PRODUCT_NAME

    param_dict = {
        'titlename': u'子订单详情',
        'sub_order': inst,
        'nav_bar': nav_bar,
        'DEFAULT_PRODUCT_NAME': DEFAULT_PRODUCT_NAME
    }
    param_dict.update(product_types=apis.product.get_product_types())
    param_dict.update(products=json.dumps(apis.product.get_products()))
    param_dict.update(harbor_list=apis.harbor.get_harbor_list())
    purl = request.args.get("purl")
    if purl is None or purl == "None":
        purl = url_for("order.order_list")
    param_dict.update(purl=purl)
    return render_template("order/sub-order.html", **param_dict)
Exemple #16
0
def ajax_consignment():
    class _ConsignmentForm(Form):
        id = IntegerField("id")

    form = _ConsignmentForm(request.form)
    consignment_id = form.id.data
    if consignment_id:
        import lite_mms.apis as apis
        cons = apis.delivery.get_consignment(consignment_id)
        if not cons:
            return _(u"不存在该发货单%d" % consignment_id), 404
        elif not cons.MSSQL_ID:
            try:
                cons.persist()
            except ValueError, error:
                return unicode(error.message), 403
            return _(u"更新成功")
Exemple #17
0
def discard_report_list():
    page = request.args.get("page", 1, type=int)
    page_size = constants.ITEMS_PER_PAGE
    import lite_mms.apis as apis
    qir_list, total_cnt = apis.quality_inspection.get_qir_list(
        idx=(page - 1) * page_size,
        cnt=page_size, finished_only=True,
        result=constants.quality_inspection.DISCARD)
    pagination = Pagination(page, page_size, total_cnt)
    dr_list = [_discard_report_wrapper(qir) for qir in qir_list]
    return dict(titlename=_(u"报废单管理"), dr_list=dr_list, pagination=pagination)
    def new(cls, actor_id, work_command_id, quantity, result, pic_path,
            report_time=None):
        from lite_mms.apis.manufacture import WorkCommandWrapper

        workcommand = WorkCommandWrapper.get_work_command(
            work_command_id)
        if not workcommand:
            raise ValueError(_(u"无该工单%s" % work_command_id))
        weight = workcommand.model.processed_unit_weight * quantity
        qi_report = models.QIReport(workcommand.model, quantity, weight,
                                    result, actor_id, report_time, pic_path)
        return QIReportWrapper(do_commit(qi_report))
Exemple #19
0
def discard_report_list():
    page = request.args.get("page", 1, type=int)
    page_size = constants.ITEMS_PER_PAGE
    import lite_mms.apis as apis
    qir_list, total_cnt = apis.quality_inspection.get_qir_list(
        idx=(page - 1) * page_size,
        cnt=page_size,
        finished_only=True,
        result=constants.quality_inspection.DISCARD)
    pagination = Pagination(page, page_size, total_cnt)
    dr_list = [_discard_report_wrapper(qir) for qir in qir_list]
    return dict(titlename=_(u"报废单管理"), dr_list=dr_list, pagination=pagination)
Exemple #20
0
def delivery_task(id_):
    from lite_mms import apis
    task = apis.delivery.get_delivery_task(id_)
    if not task:
        abort(404)
    if task.weight:
        return _(u"已称重的发货任务不能删除"), 403
    try:
        task.delete()
        flash(u"删除成功")
        return "success"
    except Exception, e:
        return unicode(e), 403
Exemple #21
0
def customer_list():
    """
    return the customers, params include:
    * unload_session_id
    """
    unload_session_id = request.args.get("unload_session_id", None)
    customers = []
    if unload_session_id:
        unload_session_id = int(unload_session_id)
        from lite_mms import apis

        unload_session = apis.cargo.get_unload_session(unload_session_id)
        if not unload_session.finish_time:
            return _(u"卸货会话尚未结束"), 403
        if any(task.weight == 0 for task in unload_session.task_list):
            return _(u"请先对所有的卸货任务进行称重"), 403
        acked_customer_id_list = set([gr.customer_id for gr in
                                      unload_session.goods_receipt_list])
        customers = [c for c in unload_session.customer_list if
                     c.id not in acked_customer_id_list]
    if not customers:
        return _(u"已经对所有的用户生成了收货单"), 403
    return json.dumps([{"id": c.id, "name": c.name} for c in customers])
Exemple #22
0
def customer_list():
    """
    返回一定时间段内,有仓单的客户列表
    """
    time_span = request.args.get("time_span", "unlimited")
    if time_span not in ["unlimited", "week", "month"]:
        raise _("参数time_span非法"), 403
    if time_span == "unlimited":
        time_span = ""
    from lite_mms import apis

    customers = apis.store.get_customer_list(time_span=time_span)
    return json.dumps(
        [dict(name=c.name, abbr=c.abbr, id=c.id) for c in customers])
Exemple #23
0
def customer_list():
    """
    返回一定时间段内,有仓单的客户列表
    """
    time_span = request.args.get("time_span", "unlimited")
    if time_span not in ["unlimited", "week", "month"]:
        raise _("参数time_span非法"), 403
    if time_span == "unlimited":
        time_span = ""
    from lite_mms import apis

    customers = apis.store.get_customer_list(time_span=time_span)
    return json.dumps(
        [dict(name=c.name, abbr=c.abbr, id=c.id) for c in customers])
Exemple #24
0
 def update(cls, id_, actor_id, quantity=None, result=None, pic_path=None):
     """
     update quality inspection report in database
     """
     qir = cls.get(id_)
     if not qir:
         raise ValueError(_(u"无此报告%s" % id_))
     if quantity:
         qir.model.quantity = quantity
     if result is not None:
         qir.model.result = result
     if pic_path:
         qir.model.pic_path = pic_path
     qir.model.actor_id = actor_id
     return QIReportWrapper(do_commit(qir.model))
Exemple #25
0
    def new_order(cls, goods_receipt_id, order_type, creator_id):
        """
        create a new order in database
        :return: the newly create order if there's corresponding goods receipt
        :raise: ValueError
        """
        from lite_mms.apis import cargo

        goods_receipt = cargo.get_goods_receipt(goods_receipt_id)

        try:
            creator = models.User.query.filter_by(id=creator_id).one()
        except NoResultFound:
            raise ValueError(_(u"没有此用户%d" % creator_id))

        if order_type not in (constants.STANDARD_ORDER_TYPE,
                              constants.EXTRA_ORDER_TYPE):
            raise ValueError(_(u"非法的订单类型%d" % order_type))
        else:
            order = models.Order(goods_receipt=goods_receipt, creator=creator)
            do_commit(order)
            if order_type == constants.STANDARD_ORDER_TYPE:
                sub_orders = []
                for entry in goods_receipt.goods_receipt_entries:
                    sub_order = models.SubOrder(order=order,
                                                product=entry.product,
                                                weight=entry.weight,
                                                pic_path=entry.pic_path,
                                                harbor=entry.harbor,
                                                quantity=entry.weight,
                                                unit=u'KG',
                                                default_harbor=entry.harbor)
                    sub_orders.append(sub_order)

                do_commit(sub_orders)
            return OrderWrapper(order)
Exemple #26
0
    def new_order(cls, goods_receipt_id, order_type, creator_id):
        """
        create a new order in database
        :return: the newly create order if there's corresponding goods receipt
        :raise: ValueError
        """
        from lite_mms.apis import cargo

        goods_receipt = cargo.get_goods_receipt(goods_receipt_id)

        try:
            creator = models.User.query.filter_by(id=creator_id).one()
        except NoResultFound:
            raise ValueError(_(u"没有此用户%d" % creator_id))

        if order_type not in (
            constants.STANDARD_ORDER_TYPE, constants.EXTRA_ORDER_TYPE):
            raise ValueError(_(u"非法的订单类型%d" % order_type))
        else:
            order = models.Order(goods_receipt=goods_receipt, creator=creator)
            do_commit(order)
            if order_type == constants.STANDARD_ORDER_TYPE:
                sub_orders = []
                for entry in goods_receipt.goods_receipt_entries:
                        sub_order = models.SubOrder(order=order,
                                                    product=entry.product,
                                                    weight=entry.weight,
                                                    pic_path=entry.pic_path,
                                                    harbor=entry.harbor,
                                                    quantity=entry.weight,
                                                    unit=u'KG',
                                                    default_harbor=entry.harbor)
                        sub_orders.append(sub_order)

                do_commit(sub_orders)
            return OrderWrapper(order)
 def update(cls, id_, actor_id, quantity=None, result=None, pic_path=None):
     """
     update quality inspection report in database
     """
     qir = cls.get(id_)
     if not qir:
         raise ValueError(_(u"无此报告%s" % id_))
     if quantity:
         qir.model.quantity = quantity
     if result is not None:
         qir.model.result = result
     if pic_path:
         qir.model.pic_path = pic_path
     qir.model.actor_id = actor_id
     return QIReportWrapper(do_commit(qir.model))
Exemple #28
0
def team_performance():
    import lite_mms.apis as apis
    page = request.args.get("page", 1, type=int)
    orders, total_cnt = apis.order.get_order_list(
        (page - 1) * constants.ORDER_PER_PAGE, constants.ORDER_PER_PAGE)
    if orders is None:
        orders = []
    pagination = Pagination(page, constants.ORDER_PER_PAGE, total_cnt)

    department_list = apis.manufacture.get_department_list()
    team_list = []
    for dep in department_list:
        team_list.extend(apis.manufacture.get_team_list(dep.id))
    return dict(titlename=_(u"班组绩效管理"), order_list=orders,
                team_list=team_list, pagination=pagination, page=page)
Exemple #29
0
    def new(cls,
            actor_id,
            work_command_id,
            quantity,
            result,
            pic_path,
            report_time=None):
        from lite_mms.apis.manufacture import WorkCommandWrapper

        workcommand = WorkCommandWrapper.get_work_command(work_command_id)
        if not workcommand:
            raise ValueError(_(u"无该工单%s" % work_command_id))
        weight = workcommand.model.processed_unit_weight * quantity
        qi_report = models.QIReport(workcommand.model, quantity, weight,
                                    result, actor_id, report_time, pic_path)
        return QIReportWrapper(do_commit(qi_report))
Exemple #30
0
def team_performance():
    import lite_mms.apis as apis
    page = request.args.get("page", 1, type=int)
    orders, total_cnt = apis.order.get_order_list(
        (page - 1) * constants.ORDER_PER_PAGE, constants.ORDER_PER_PAGE)
    if orders is None:
        orders = []
    pagination = Pagination(page, constants.ORDER_PER_PAGE, total_cnt)

    department_list = apis.manufacture.get_department_list()
    team_list = []
    for dep in department_list:
        team_list.extend(apis.manufacture.get_team_list(dep.id))
    return dict(titlename=_(u"班组绩效管理"),
                order_list=orders,
                team_list=team_list,
                pagination=pagination,
                page=page)
Exemple #31
0
def ajax_sub_order():
    sub_order_id = request.args.get('id', type=int)
    if not sub_order_id:
        return _(u"不存在该订单"), 404
    from lite_mms import apis

    inst = apis.order.get_sub_order(sub_order_id)
    if not inst:
        return "no sub order with id " + str(sub_order_id), 404
    from lite_mms.basemain import nav_bar
    from lite_mms.constants import DEFAULT_PRODUCT_NAME

    param_dict = {'titlename': u'子订单详情', 'sub_order': inst, 'nav_bar': nav_bar,
                  'DEFAULT_PRODUCT_NAME': DEFAULT_PRODUCT_NAME}
    param_dict.update(product_types=apis.product.get_product_types())
    param_dict.update(products=json.dumps(apis.product.get_products()))
    param_dict.update(harbor_list=apis.harbor.get_harbor_list())
    purl = request.args.get("purl")
    if purl is None or purl == "None":
        purl = url_for("order.order_list")
    param_dict.update(purl=purl)
    return render_template("order/sub-order.html", **param_dict)
Exemple #32
0
def login():
    username = request.args.get("username", type=str)
    password = request.args.get("password", type=str)
    if not username or not password:
        return _(u"需要username或者password字段"), 403
    try:
        import lite_mms.apis as apis

        user = apis.auth.authenticate(username, password)
        if not user.can_login_client:
            return json.dumps({
                'reason': u'该用户不能在客户端登录'
            }), 403
    except AuthenticateFailure as inst:
        return json.dumps({
            'reason': unicode(inst)
        }), 403
    return json.dumps(
        dict(username=user.username,
             teamID=",".join([str(team.id) for team in user.team_list]) if user.team_list else "",
             userID=user.id, departmentID=",".join([str(department.id) for department in
                                                    user.department_list]) if user.department_list else "",
             userGroup=user.groups[0].id, token=user.get_auth_token()))
Exemple #33
0
def login():
    username = request.args.get("username", type=str)
    password = request.args.get("password", type=str)
    if not username or not password:
        return _(u"需要username或者password字段"), 403
    try:
        import lite_mms.apis as apis

        user = apis.auth.authenticate(username, password)
        if not user.can_login_client:
            return json.dumps({'reason': u'该用户不能在客户端登录'}), 403
    except AuthenticateFailure as inst:
        return json.dumps({'reason': unicode(inst)}), 403
    return json.dumps(
        dict(username=user.username,
             teamID=",".join([str(team.id) for team in user.team_list])
             if user.team_list else "",
             userID=user.id,
             departmentID=",".join([
                 str(department.id) for department in user.department_list
             ]) if user.department_list else "",
             userGroup=user.groups[0].id,
             token=user.get_auth_token()))
Exemple #34
0
    form = _ConsignmentForm(request.form)
    consignment_id = form.id.data
    if consignment_id:
        import lite_mms.apis as apis
        cons = apis.delivery.get_consignment(consignment_id)
        if not cons:
            return _(u"不存在该发货单%d" % consignment_id), 404
        elif not cons.MSSQL_ID:
            try:
                cons.persist()
            except ValueError, error:
                return unicode(error.message), 403
            return _(u"更新成功")
    else:
        return _(u"数据错误"), 404


@delivery_page.route("/ajax/customer-list")
@ajax_call
def customer_list():
    """
    return the customers, params include:
    * delivery_session_id
    """
    delivery_session_id = request.args.get("delivery_session_id", type=int)
    customers = []
    if delivery_session_id is not None:
        import lite_mms.apis as apis

        delivery_session = apis.delivery.get_delivery_session(
Exemple #35
0
def index():
    return dict(titlename=_(u"运营管理"))
Exemple #36
0
            return "", 201
    else:
        finished_store_bill_list = [
            get_or_404(models.StoreBill, store_bill_id)
            for store_bill_id in finished_store_bill_id_list
        ]
        try:
            dt = create_delivery_task(ds, remain, finished_store_bill_list,
                                      unfinished_store_bill, current_user,
                                      is_finished)
            ret = dict(id=dt.actor_id,
                       actor_id=dt.actor_id,
                       store_bill_id_list=dt.store_bill_id_list)
            return json.dumps(ret)
        except KeyError:
            return _(u"不能添加发货任务"), 403
        except (ValueError, PermissionDenied) as e:
            return unicode(e), 403


def create_delivery_task(ds, remain, finished_store_bill_id_list,
                         unfinished_store_bill, loader, is_finished):
    from lite_mms.portal.delivery.fsm import fsm

    fsm.reset_obj(ds)
    fsm.next(constants.delivery.ACT_LOAD, loader)
    dt = apis.delivery.new_delivery_task(loader.id,
                                         finished_store_bill_id_list,
                                         unfinished_store_bill, remain)
    if is_finished:  # 发货会话结束
        dt.update(is_last=True)
Exemple #37
0
def delivery_task():
    is_finished = request.args.get("is_finished", type=int)
    remain = request.args.get("remain", type=int)

    json_sb_list = json.loads(request.data)
    if len(json_sb_list) == 0:
        return _(u"至少需要一个仓单"), 403
    finished_store_bill_id_list = []
    unfinished_store_bill_id_list = []
    for json_sb in json_sb_list:
        if json_sb["is_finished"]:
            try:
                finished_store_bill_id_list.append(
                    int(json_sb["store_bill_id"]))
            except ValueError:
                return _(u"仓单id只能为非整数"), 403
        else:
            try:
                unfinished_store_bill_id_list.append(
                    int(json_sb["store_bill_id"]))
            except ValueError:
                return _(u"仓单id只能为非整数"), 403
    if len(unfinished_store_bill_id_list) > 1:
        return _(u"最多只有一个仓单可以部分完成"), 403
    if unfinished_store_bill_id_list:
        if not remain:
            return _(u"需要remain字段"), 403

    delivery_session_id = request.args.get("sid", type=int)

    if yawf.token_bound(constants.work_flow.DELIVERY_TASK_WITH_ABNORMAL_WEIGHT,
                        str(delivery_session_id)):
        return u'本卸货会话有待处理的工作流,请先敦促工作人员处理该工作流', 403

    ds = apis.delivery.get_delivery_session(delivery_session_id)
    if not ds:
        return _(u"需要发货会话字段"), 403
    id_list = [store_bill.id for store_bill in ds.store_bill_list]
    for id_ in finished_store_bill_id_list + unfinished_store_bill_id_list:
        if id_ not in id_list:
            return _(u"仓单%s未关联到发货会话%s" % (id_, delivery_session_id)), 403

    unfinished_store_bill = get_or_404(
        models.StoreBill, unfinished_store_bill_id_list[0]
    ) if unfinished_store_bill_id_list else None
    if unfinished_store_bill and apis.delivery.store_bill_remain_unacceptable(
            unfinished_store_bill, remain):
        try:
            doc = database.codernity_db.insert(
                dict(delivery_session_id=delivery_session_id,
                     remain=remain,
                     finished_store_bill_id_list=finished_store_bill_id_list,
                     unfinished_store_bill_id=unfinished_store_bill.id,
                     loader_id=current_user.id,
                     is_last_task=is_finished))
            # 保存token,以避免重复提交工作流, 显然,对于一个卸货会话而言,只能同时存在一个正在处理的工作流
            work_flow = yawf.new_work_flow(
                constants.work_flow.DELIVERY_TASK_WITH_ABNORMAL_WEIGHT,
                lambda work_flow: models.Node(
                    work_flow=work_flow,
                    name=u"生成异常剩余重量的发货任务",
                    policy_name='CreateDeliveryTaskWithAbnormalWeight'),
                tag_creator=lambda work_flow: doc['_id'],
                token=str(delivery_session_id))
            work_flow.start()
        except yawf.exceptions.WorkFlowDelayed, e:
            return "", 201
Exemple #38
0
# -*- coding: utf-8 -*-
from lite_mms.utilities import _


STANDARD_RECEIPT_TEMPLATE_ID = 1
EXTRA_RECEIPT_TEMPLATE_ID = 2
DEFAULT_PRODUCT_TYPE_NAME = _(u"默认加工件")
DEFAULT_PRODUCT_NAME = _(u"默认加工件")
DEFAULT_TECH_REQ = _(u"默认")

ITEMS_PER_PAGE = 15
UNLOAD_SESSION_PER_PAGE = 15
STORE_BILL_PER_PAGE = 15
DELIVERY_SESSION_PER_PAGE = 15
ORDER_PER_PAGE = 15

# order types

STANDARD_ORDER_TYPE = 1
EXTRA_ORDER_TYPE = 2

EXTRA_ORDER_TYPE_NAME = u"计件"
STANDARD_ORDER_TYPE_NAME = u"计重"

ADMIN_USER_ID = 1

PRINT_COUNT_PER_PAGE = u"print_count_per_page"
Exemple #39
0
def index():
    return dict(titlename=_(u"运营管理"))