Beispiel #1
0
class StoreBill(db.Model):
    __modelname__ = u"仓单"
    __tablename__ = "TB_STORE_BILL"

    id = db.Column(db.Integer, primary_key=True)

    harbor_name = db.Column(db.String(32), db.ForeignKey('TB_HABOR.name'))
    harbor = db.relationship("Harbor")
    sub_order_id = db.Column(db.Integer, db.ForeignKey("TB_SUB_ORDER.id"))
    sub_order = db.relationship("SubOrder",
                                backref=db.backref(
                                    "store_bill_list",
                                    cascade="all, delete-orphan"))
    qir_id = db.Column(db.Integer, db.ForeignKey("TB_QI_REPORT.id"))
    qir = db.relationship("QIReport",
                          backref=db.backref("store_bill_list", cascade="all"))
    quantity = db.Column(db.Integer)
    weight = db.Column(db.Integer, default=0)
    customer_id = db.Column(db.Integer, db.ForeignKey("TB_CUSTOMER.id"))
    customer = db.relationship("Customer")
    delivery_session_id = db.Column(db.Integer,
                                    db.ForeignKey("TB_DELIVERY_SESSION.id"),
                                    nullable=True)
    delivery_session = db.relationship("DeliverySession",
                                       backref="store_bill_list")
    delivery_task_id = db.Column(db.Integer,
                                 db.ForeignKey("TB_DELIVERY_TASK.id"),
                                 nullable=True)
    delivery_task = db.relationship("DeliveryTask", backref="store_bill_list")
    create_time = db.Column(db.DateTime)
    printed = db.Column(db.Boolean, default=False)

    @property
    def unit_weight(self):
        try:
            return self.weight / float(self.quantity)
        except ZeroDivisionError:
            return 0

    def __init__(self, qir, create_time=None):
        self.qir = qir
        self.weight = qir.weight
        self.quantity = qir.quantity
        self.customer_id = qir.work_command.sub_order.order.goods_receipt \
            .customer_id
        self.create_time = create_time or datetime.now()
        self.sub_order = qir.work_command.sub_order

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<StoreBill %d>" % self.id
Beispiel #2
0
class DeliverySession(db.Model):
    __modelname__ = u"发货会话"
    __tablename__ = "TB_DELIVERY_SESSION"

    id = db.Column(db.Integer, primary_key=True)
    plate = db.Column(db.String(32),
                      db.ForeignKey("TB_PLATE.name"),
                      nullable=False)
    plate_ = db.relationship("Plate")
    tare = db.Column(db.Integer, nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.now)
    finish_time = db.Column(db.DateTime)
    with_person = db.Column(db.Boolean, default=False)
    delivery_task_list = db.relationship("DeliveryTask",
                                         backref=db.backref("delivery_session",
                                                            uselist=False),
                                         cascade="all, delete-orphan")
    status = db.Column(db.Integer,
                       default=constants.delivery.STATUS_LOADING,
                       nullable=False)

    def __unicode__(self):
        return self.plate

    def __repr__(self):
        return "<DeliverySession %d>" % self.id
Beispiel #3
0
class UnloadTask(db.Model):
    __modelname__ = u"卸货任务"
    __tablename__ = "TB_UNLOAD_TASK"

    id = db.Column(db.Integer, primary_key=True)
    session_id = db.Column(db.Integer, db.ForeignKey('TB_UNLOAD_SESSION.id'))
    unload_session = db.relationship("UnloadSession",
                                     backref=db.backref(
                                         "task_list",
                                         cascade="all, delete-orphan"))
    harbor_name = db.Column(db.String(32), db.ForeignKey('TB_HABOR.name'))
    harbor = db.relationship("Harbor")
    customer_id = db.Column(db.Integer, db.ForeignKey('TB_CUSTOMER.id'))
    customer = db.relationship("Customer")
    creator_id = db.Column(db.Integer, db.ForeignKey('TB_USER.id'))
    creator = db.relationship("User")
    pic_path = db.Column(db.String(256))
    create_time = db.Column(db.DateTime, default=datetime.now)
    weight = db.Column(db.Integer, default=0)
    product_id = db.Column(db.Integer, db.ForeignKey("TB_PRODUCT.id"))
    product = db.relationship("Product")
    is_last = db.Column(db.Boolean, default=False)

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<UnloadTask %d>" % self.id
Beispiel #4
0
class QIReport(db.Model):
    __modelname__ = u"质检报告"
    __tablename__ = "TB_QI_REPORT"

    id = db.Column(db.Integer, primary_key=True)
    work_command_id = db.Column(db.Integer,
                                db.ForeignKey("TB_WORK_COMMAND.id"))
    generated_work_command_id = db.Column(db.Integer,
                                          db.ForeignKey("TB_WORK_COMMAND.id"))
    generated_work_command = db.relationship(
        "WorkCommand",
        backref=db.backref("parent_qir", uselist=False),
        primaryjoin="WorkCommand.id==QIReport.generated_work_command_id")
    quantity = db.Column(db.Integer)
    weight = db.Column(db.Integer)
    result = db.Column(db.Integer)
    report_time = db.Column(db.DateTime)
    actor_id = db.Column(db.Integer, db.ForeignKey("TB_USER.id"))
    actor = db.relationship(User)
    pic_path = db.Column(db.String(256))

    def __init__(self,
                 work_command,
                 quantity,
                 weight,
                 result,
                 actor_id,
                 report_time=None,
                 pic_path=""):
        self.work_command = work_command
        self.quantity = quantity
        self.weight = weight
        self.result = result
        self.actor_id = actor_id
        self.report_time = report_time or datetime.now()
        self.pic_path = pic_path

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<QIReport %d>" % self.id
Beispiel #5
0
class ConsignmentProduct(db.Model):
    __modelname__ = u"发货单产品"
    __tablename__ = "TB_CONSIGNMENT_PRODUCT"

    id = db.Column(db.Integer, primary_key=True)
    consignment_id = db.Column(db.Integer,
                               db.ForeignKey("TB_CONSIGNMENT.id"),
                               nullable=False)
    consignment = db.relationship("Consignment",
                                  backref=db.backref(
                                      "product_list",
                                      cascade="all, delete-orphan"))
    product_id = db.Column(db.Integer,
                           db.ForeignKey("TB_PRODUCT.id"),
                           nullable=False)
    product = db.relationship("Product")
    delivery_task_id = db.Column(db.Integer,
                                 db.ForeignKey("TB_DELIVERY_TASK.id"),
                                 nullable=False)
    delivery_task = db.relationship("DeliveryTask")
    weight = db.Column(db.Integer)
    quantity = db.Column(db.Integer)
    unit = db.Column(db.String(16), default=u"桶")
    spec = db.Column(db.String(64))
    type = db.Column(db.String(64))
    returned_weight = db.Column(db.Integer)
    team_id = db.Column(db.Integer, db.ForeignKey("TB_TEAM.id"))
    team = db.relationship("Team")

    def __init__(self, product, delivery_task, consignment):
        self.product = product
        self.delivery_task = delivery_task
        self.consignment = consignment

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<DeliveryProduct %d>" % self.id
Beispiel #6
0
class GoodsReceipt(db.Model):
    __modelname__ = u"收货单"
    __tablename__ = "TB_GOODS_RECEIPT"

    id = db.Column(db.Integer, primary_key=True)
    receipt_id = db.Column(db.String(15), unique=True)
    customer_id = db.Column(db.Integer, db.ForeignKey('TB_CUSTOMER.id'))
    customer = db.relationship(Customer)
    unload_session_id = db.Column(db.Integer,
                                  db.ForeignKey('TB_UNLOAD_SESSION.id'))
    create_time = db.Column(db.DateTime, default=datetime.now)
    printed = db.Column(db.Boolean, default=False)
    order = db.relationship("Order",
                            backref=db.backref("goods_receipt", uselist=False),
                            cascade="all, delete-orphan",
                            uselist=False)
    creator_id = db.Column(db.Integer, db.ForeignKey("TB_USER.id"))
    creator = db.relationship("User")

    def __init__(self,
                 customer,
                 unload_session,
                 create_time=None,
                 creator=None):
        self.customer = customer
        self.unload_session = unload_session
        self.create_time = create_time or datetime.now()
        self.creator = creator
        self.receipt_id = self.id_generator()

    def id_generator(self):
        return self.create_time.strftime('%Y%m%d%H%M%S') + \
               str((self.unload_session.id + self.customer.id) % 100)[0]

    def __unicode__(self):
        return self.receipt_id

    def __repr__(self):
        return "<GoodsReceipt %d>" % self.id
Beispiel #7
0
class WorkCommand(db.Model, _ResyncMixin):
    __modelname__ = u"工单"
    __tablename__ = "TB_WORK_COMMAND"

    id = db.Column(db.Integer, primary_key=True)
    create_time = db.Column(db.DateTime)
    department = db.relationship("Department",
                                 order_by=User.id,
                                 backref="work_comman_list")
    department_id = db.Column(db.Integer,
                              db.ForeignKey("TB_DEPARTMENT.id"),
                              nullable=True)
    last_mod = db.Column(db.DateTime, doc=u"上次对工单修改的时间")
    completed_time = db.Column(db.DateTime, doc=u"生产完毕的时间")
    org_cnt = db.Column(db.Integer)
    org_weight = db.Column(db.Integer)
    urgent = db.Column(db.Boolean)
    previous_procedure_id = db.Column(db.Integer,
                                      db.ForeignKey("TB_PROCEDURE.id"))
    previous_procedure = db.relationship("Procedure",
                                         primaryjoin="Procedure"
                                         ".id==WorkCommand"
                                         ".previous_procedure_id")
    procedure_id = db.Column(db.Integer, db.ForeignKey("TB_PROCEDURE.id"))
    procedure = db.relationship("Procedure",
                                primaryjoin="Procedure.id==WorkCommand"
                                ".procedure_id")
    processed_cnt = db.Column(db.Integer)
    processed_weight = db.Column(db.Integer)
    status = db.Column(db.Integer)
    sub_order_id = db.Column(db.Integer, db.ForeignKey("TB_SUB_ORDER.id"))
    tag = db.Column(db.String(32))
    team = db.relationship("Team", backref="work_comman_list")
    team_id = db.Column(db.Integer, db.ForeignKey("TB_TEAM.id"), nullable=True)
    tech_req = db.Column(db.String(32))
    qir_list = db.relationship("QIReport",
                               backref="work_command",
                               cascade="all, delete-orphan",
                               primaryjoin="WorkCommand.id==QIReport"
                               ".work_command_id")
    pic_path = db.Column(db.String(256))
    handle_type = db.Column(db.Integer)
    previous_work_command_id = db.Column(db.Integer,
                                         db.ForeignKey("TB_WORK_COMMAND.id"))
    previous_work_command = db.relationship(
        "WorkCommand",
        backref=db.backref("next_work_command_list"),
        primaryjoin="WorkCommand.id==WorkCommand.previous_work_command_id",
        uselist=False,
        remote_side=id)

    @property
    def unit_weight(self):
        try:
            return self.org_weight / float(self.org_cnt)
        except ZeroDivisionError:
            return 0

    @property
    def processed_unit_weight(self):
        try:
            return self.processed_weight / float(self.processed_cnt)
        except ZeroDivisionError:
            return 0

    def __init__(self,
                 sub_order,
                 org_weight,
                 procedure,
                 urgent=False,
                 status=constants.work_command.STATUS_DISPATCHING,
                 department=None,
                 create_time=None,
                 last_mod=datetime.now(),
                 processed_weight=0,
                 team=None,
                 previous_procedure=None,
                 tag="",
                 tech_req="",
                 org_cnt=0,
                 processed_cnt=0,
                 pic_path="",
                 handle_type=constants.work_command.HT_NORMAL,
                 previous_work_command=None):
        self.sub_order = sub_order
        self.urgent = urgent
        self.org_weight = org_weight
        self.procedure = procedure
        self.status = status
        self.create_time = create_time or datetime.now()
        self.last_mod = last_mod
        self.processed_weight = processed_weight
        self.team = team
        self.department = department
        self.previous_procedure = previous_procedure
        self.tag = tag
        self.tech_req = tech_req
        self.org_cnt = org_cnt
        self.processed_cnt = processed_cnt
        self.pic_path = pic_path
        self.handle_type = handle_type
        self.previous_work_command = previous_work_command

    def set_status(self, new_status):
        """
        set new status, and UPDATE last_mod field, so DON'T UPDATE STATUS
        DIRECTLY!
        """
        self.status = new_status
        self.last_mod = datetime.now()

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<WorkCommand %d>" % self.id
Beispiel #8
0
class SubOrder(db.Model, _ResyncMixin):
    __modelname__ = u"子订单"
    __tablename__ = "TB_SUB_ORDER"

    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey("TB_PRODUCT.id"))
    product = db.relationship("Product")

    task_id = db.Column(db.Integer, db.ForeignKey("TB_UNLOAD_TASK.id"))
    unload_task = db.relationship("UnloadTask",
                                  backref=db.backref("sub_order",
                                                     uselist=False),
                                  uselist=False)

    default_harbor_name = db.Column(db.String(32),
                                    db.ForeignKey("TB_HABOR.name"))
    default_harbor = db.relationship(
        "Harbor", primaryjoin="Harbor.name == SubOrder.default_harbor_name")
    spec = db.Column(db.String(64))
    type = db.Column(db.String(64))
    weight = db.Column(db.Integer, default=0)
    harbor_name = db.Column(db.String(32), db.ForeignKey('TB_HABOR.name'))
    harbor = db.relationship("Harbor",
                             primaryjoin="Harbor.name == SubOrder.harbor_name")
    order_id = db.Column(db.Integer, db.ForeignKey("TB_ORDER.id"))
    urgent = db.Column(db.Boolean)
    returned = db.Column(db.Boolean)
    pic_path = db.Column(db.String(256))
    tech_req = db.Column(db.String(64))
    create_time = db.Column(db.DateTime)
    finish_time = db.Column(db.DateTime)
    quantity = db.Column(db.Integer, default=0)
    unit = db.Column(db.String(16), default=u'')
    due_time = db.Column(db.Date)
    order_type = db.Column(db.Integer)
    remaining_quantity = db.Column(db.Integer)
    work_command_list = db.relationship("WorkCommand",
                                        backref=db.backref("sub_order",
                                                           uselist=False),
                                        cascade="all, delete-orphan")

    @property
    def unit_weight(self):
        try:
            return self.weight / float(self.quantity)
        except ZeroDivisionError:
            return 0

    def __init__(self,
                 product,
                 weight,
                 harbor,
                 order,
                 quantity,
                 unit,
                 order_type=constants.STANDARD_ORDER_TYPE,
                 create_time=None,
                 finish_time=None,
                 urgent=False,
                 returned=False,
                 pic_path="",
                 tech_req="",
                 due_time=None,
                 spec="",
                 type="",
                 default_harbor=None):
        self.product = product
        self.spec = spec
        self.type = type
        self.weight = weight
        self.harbor = harbor
        self.remaining_quantity = self.quantity = quantity
        self.unit = unit
        self.order = order
        self.create_time = create_time or datetime.now()
        self.finish_time = finish_time
        self.urgent = urgent
        self.returned = returned
        self.pic_path = pic_path
        self.tech_req = tech_req
        self.due_time = due_time
        self.order_type = order_type
        self.default_harbor = default_harbor

    def __unicode__(self):
        return unicode(self.id)

    def __repr__(self):
        return "<SubOrder %d>" % self.id