def update_store_bill(cls, store_bill_id, **kwargs): store_bill = StoreBillWrapper.get_store_bill(store_bill_id) if not store_bill: raise ValueError(u'没有此仓单%d' % store_bill_id) if kwargs.get("printed", None): store_bill.model.printed = kwargs.get("printed") if kwargs.get("harbor"): try: harbor = models.Harbor.query.filter_by( name=kwargs.get("harbor")).one() except NoResultFound: raise ValueError(u'没有此装卸点%s' % kwargs.get("harbor")) store_bill.model.harbor = harbor if kwargs.get("delivery_session_id"): store_bill.delivery_session_id = kwargs.get("delivery_session_id") store_bill.delivery_task_id = kwargs.get("delivery_task_id") if kwargs.get("weight"): store_bill.weight = kwargs["weight"] if kwargs.get("quantity"): store_bill.quantity = kwargs["quantity"] do_commit(store_bill.model) store_bill.do_update_log() return StoreBillWrapper(do_commit(store_bill))
def emit(self, record): log = Log() obj = getattr(record, "obj", None) if obj: log.obj = unicode(obj) obj_cls = getattr(record, "obj_cls", None) if obj_cls: log.obj_cls = obj_cls else: if obj: if isinstance(obj, ModelWrapper): log.obj_cls = obj.model.__class__.__name__ else: log.obj_cls = obj.__class__.__name__ obj_pk = getattr(record, "obj_pk", None) if obj_pk: log.obj_pk = obj_pk log.actor = getattr(record, "actor", None) log.action = getattr(record, "action", "") log.create_time = datetime.now() log.message = record.msg[:Log.message.property.columns[0].type.length] #log.name = record.name #log.level = record.levelname #log.module = record.module #log.func_name = record.funcName #log.line_no = record.lineno #log.thread = record.thread #log.thread_name = record.threadName #log.process = record.process #log.args = str(record.args) do_commit(log)
def _(step): from random import choice import string plate_ = do_commit(models.Plate(name=u"浙%s %s%s%s%s%s" % ( choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase)))) return do_commit(models.UnloadSession(plate_=plate_, gross_weight=1000))
def _(step, us): us = refresh(us) for ut in us.task_list: ut.weight = 4000 from lite_mms.constants.cargo import STATUS_LOADING us.status = STATUS_LOADING do_commit(us)
def update(self, finish_time): """ update the unload session's scalar attribute persistently only finish_time could be updated :return: the updated unload session if succeed, otherwise None """ self.model.finish_time = finish_time do_commit(self.model)
def gc_goods_receipts(self): """ delete the goods_receipt which has not entry converted from current unload_session's unload_task_list """ for gr in self.goods_receipt_list: if gr.customer.id not in self.customer_id_list: do_commit(gr.model, "delete")
def gc_consignment_list(self): """ delete the consignment which has not entry converted from current delivery_session's delivery_task """ for cn in self.consignment_list: if cn.customer.id not in self.customer_id_list: do_commit(cn.model, "delete")
def _(step,plate,tare, customer, product): delivery_session = do_commit( models.DeliverySession(plate_=plate, tare=tare, status=constants.delivery.STATUS_CLOSED)) delivery_task = do_commit(models.DeliveryTask(actor_id=None,delivery_session=delivery_session)) con = do_commit((models.Consignment(customer=customer, delivery_session=delivery_session, pay_in_cash=True))) do_commit(models.ConsignmentProduct(consignment=con, delivery_task=delivery_session.delivery_task_list[0], product=product)) return delivery_session
def _f(*args, **kwargs): ret = f(*args, **kwargs) from lite_mms.database import db if isinstance(ret, db.Model): from lite_mms.utilities import do_commit do_commit(ret) return ret
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"
def post_types(data): count = 0 for type in data: try: models.ProductType.query.filter( models.ProductType.name == type["name"]).one() except NoResultFound: do_commit( models.ProductType(name=type["name"], MSSQL_ID=type["id"])) count += 1 return u"成功添加%d条产品类型信息" % count
def _(step): from random import choice import string plate_ = do_commit( models.Plate( name=u"浙%s %s%s%s%s%s" % (choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase)))) return do_commit(models.UnloadSession(plate_=plate_, gross_weight=1000))
def post_customers(data): count = 0 for customer in data: try: models.Customer.query.filter( models.Customer.name == customer["name"]).one() except NoResultFound: do_commit(models.Customer(name=customer["name"], abbr=customer["short"], MSSQL_ID=customer["id"])) count += 1 return u"成功添加%d条客户信息" % count
def side_effect(self, **kwargs): if self.last_action == constants.work_command.ACT_QUICK_CARRY_FORWARD: old_wc = self.sm.obj new_wc = models.WorkCommand(sub_order=old_wc.sub_order, org_weight=old_wc.processed_weight, procedure=old_wc.procedure, status=constants.work_command .STATUS_QUALITY_INSPECTING, team=old_wc.team, department=old_wc.department, previous_procedure=old_wc .previous_procedure, tag=old_wc.tag, tech_req=old_wc.tech_req, org_cnt=old_wc.processed_cnt, pic_path=old_wc.pic_path, handle_type=old_wc.handle_type, processed_weight=old_wc.processed_weight, processed_cnt=old_wc.processed_cnt, previous_work_command=old_wc) new_wc.completed_time = datetime.now() remain_quantity = old_wc.org_cnt - old_wc.processed_cnt if remain_quantity <= 0: remain_quantity = 1 remain_weight = int( self.sm.obj.unit_weight * remain_quantity) old_wc.org_cnt = remain_quantity old_wc.org_weight = remain_weight old_wc.processed_cnt = 0 old_wc.processed_weight = 0 do_commit([old_wc, new_wc]) else: self.sm.obj.set_status(constants.work_command.STATUS_ENDING) if "team" in kwargs: # when it comes by ACT_ASSIGN self.sm.obj.team = kwargs["team"] if self.last_status == constants.work_command.STATUS_ENDING: try: self.sm.obj.processed_weight += kwargs["weight"] except KeyError: raise InvalidAction(_(u"该操作需要weight字段")) if self.sm.obj.sub_order.order_type == constants.EXTRA_ORDER_TYPE: # 计件类型 try: self.sm.obj.processed_cnt += kwargs["quantity"] except KeyError: raise InvalidAction(_(u"该操作需要quantity字段")) else: # 普通类型 self.sm.obj.processed_cnt = self.sm.obj \ .processed_weight
def _(step, customer, harbor, plate, product): us = do_commit(models.UnloadSession(plate_=plate, gross_weight=123123123)) from lite_mms.constants.cargo import STATUS_CLOSED us.status = STATUS_CLOSED import datetime us.finish_time = datetime.datetime.now() do_commit(us) ut = do_commit(models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False)) return us
def create_or_update_consignment(customer_id, delivery_session_id, pay_in_cash): try: cn = ConsignmentWrapper(models.Consignment.query.filter( models.Consignment.customer_id == customer_id).filter( models.Consignment.delivery_session_id == delivery_session_id).one()) cn.pay_in_cash = pay_in_cash if cn.stale: cn.add_product_entries() cn.stale = False do_commit(cn) return cn except NoResultFound: return new_consignment(customer_id, delivery_session_id, pay_in_cash=pay_in_cash)
def side_effect(self, **kwargs): if self.last_action == constants.work_command.ACT_QUICK_CARRY_FORWARD: old_wc = self.sm.obj new_wc = models.WorkCommand( sub_order=old_wc.sub_order, org_weight=old_wc.processed_weight, procedure=old_wc.procedure, status=constants.work_command.STATUS_QUALITY_INSPECTING, team=old_wc.team, department=old_wc.department, previous_procedure=old_wc.previous_procedure, tag=old_wc.tag, tech_req=old_wc.tech_req, org_cnt=old_wc.processed_cnt, pic_path=old_wc.pic_path, handle_type=old_wc.handle_type, processed_weight=old_wc.processed_weight, processed_cnt=old_wc.processed_cnt, previous_work_command=old_wc) new_wc.completed_time = datetime.now() remain_quantity = old_wc.org_cnt - old_wc.processed_cnt if remain_quantity <= 0: remain_quantity = 1 remain_weight = int(self.sm.obj.unit_weight * remain_quantity) old_wc.org_cnt = remain_quantity old_wc.org_weight = remain_weight old_wc.processed_cnt = 0 old_wc.processed_weight = 0 do_commit([old_wc, new_wc]) else: self.sm.obj.set_status(constants.work_command.STATUS_ENDING) if "team" in kwargs: # when it comes by ACT_ASSIGN self.sm.obj.team = kwargs["team"] if self.last_status == constants.work_command.STATUS_ENDING: try: self.sm.obj.processed_weight += kwargs["weight"] except KeyError: raise InvalidAction(_(u"该操作需要weight字段")) if self.sm.obj.sub_order.order_type == constants.EXTRA_ORDER_TYPE: # 计件类型 try: self.sm.obj.processed_cnt += kwargs["quantity"] except KeyError: raise InvalidAction(_(u"该操作需要quantity字段")) else: # 普通类型 self.sm.obj.processed_cnt = self.sm.obj \ .processed_weight
def _(step, customer, harbor, product): from random import choice import string plate_ = do_commit(models.Plate(name=u"浙%s %s%s%s%s%s" % ( choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase)))) us = do_commit(models.UnloadSession(plate_=plate_, gross_weight=100000)) from lite_mms.constants.cargo import STATUS_WEIGHING ut = do_commit(models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False)) us.status = STATUS_WEIGHING return us
def new_delivery_session(cls, plate, tare, with_person=False): """create delivery session :param cls: :param plate: :param tare: :return:a newly delivery session """ plate = plate.upper() try: models.Plate.query.filter(models.Plate.name == plate).one() except NoResultFound: do_commit(models.Plate(name=plate)) return DeliverySessionWrapper( do_commit(models.DeliverySession(plate, tare, with_person)))
def upgrade(): from lite_mms.models import ConsignmentProduct op.create_table( ConsignmentProduct.__tablename__, Column('id', Integer(), primary_key=True, nullable=False), Column('consignment_id', Integer(), ForeignKey('TB_CONSIGNMENT.id'), nullable=False), Column('product_id', Integer(), ForeignKey('TB_PRODUCT.id'), nullable=False), Column('delivery_task_id', Integer(), ForeignKey('TB_DELIVERY_TASK.id'), nullable=False), Column('weight', Integer()), Column('quantity', Integer()), Column('unit', String(length=16), default=''), Column('spec', String(length=64)), Column('type', String(length=64)), Column('returned_weight', Integer()), Column('team_id', Integer(), ForeignKey('TB_TEAM.id'), nullable=True)) from lite_mms.utilities import do_commit from lite_mms.apis.delivery import get_delivery_session_list delivery_session_list = get_delivery_session_list()[0] for delivery_session in delivery_session_list: for consignment in delivery_session.consignment_list: for t in delivery_session.delivery_task_list: if t.customer: if t.customer.id == consignment.customer_id: p = ConsignmentProduct(t.product, t, consignment) if t.team_list: p.team = t.team_list[0] p.weight = t.weight p.returned_weight = t.returned_weight if not t.quantity: t.quantity = sum( store_bill.quantity for store_bill in t.store_bill_list) p.quantity = t.quantity sb = t.sub_order_list.next() p.unit = sb.unit p.spec = sb.spec p.type = sb.type do_commit((p, t)) else: do_commit(t, "delete")
def update(self, **kwargs): if self.model.order.dispatched: raise ValueError(u"已下发的订单不能再修改") for k, v in kwargs.items(): if hasattr(self.model, k) and v != u'': if k.__eq__("due_time"): setattr(self.model, k, datetime.strptime(v, '%Y-%m-%d')) continue setattr(self.model, k, v) if k.__eq__( "weight") and self.order_type == constants.STANDARD_ORDER_TYPE: setattr(self.model, "quantity", v) if k.__eq__("quantity") and not self.model.order.dispatched: self.model.remaining_quantity = v do_commit(self.model)
def post_product(data): count = 0 for k, v in data.items(): product_type = models.ProductType.query.filter( models.ProductType.MSSQL_ID == int(k)).one() for product in v: try: models.Product.query.filter( models.Product.name == product["name"]).filter( models.Product.product_type == product_type).one() except NoResultFound: do_commit(models.Product(product["name"], product_type, MSSQL_ID=product["id"])) count += 1 return u"成功添加%d条产品信息" % count
def new_delivery_session(cls, plate, tare, with_person=False): """create delivery session :param cls: :param plate: :param tare: :return:a newly delivery session """ plate = plate.upper() try: models.Plate.query.filter( models.Plate.name == plate).one() except NoResultFound: do_commit(models.Plate(name=plate)) return DeliverySessionWrapper( do_commit(models.DeliverySession(plate, tare, with_person)))
def new_unload_session(plate, gross_weight, with_person=False): """ create an unload session :return: the newly created unload session """ plate = plate.upper() try: models.Plate.query.filter( models.Plate.name == plate).one() except NoResultFound: do_commit(models.Plate(name=plate)) return UnloadSessionWrapper(do_commit( models.UnloadSession(plate=plate, gross_weight=gross_weight, with_person=with_person)))
def _(step, us, customer, harbor, product): from lite_mms.constants.cargo import STATUS_WEIGHING ut = do_commit(models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False)) us.status = STATUS_WEIGHING return ut
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))
def update(self, **kwargs): if self.model.order.dispatched: raise ValueError(u"已下发的订单不能再修改") for k, v in kwargs.items(): if hasattr(self.model, k) and v != u'': if k.__eq__("due_time"): setattr(self.model, k, datetime.strptime(v, '%Y-%m-%d')) continue setattr(self.model, k, v) if k.__eq__( "weight" ) and self.order_type == constants.STANDARD_ORDER_TYPE: setattr(self.model, "quantity", v) if k.__eq__("quantity") and not self.model.order.dispatched: self.model.remaining_quantity = v do_commit(self.model)
def add_product_entry(self, delivery_task): p = models.ConsignmentProduct(delivery_task.product, delivery_task, self) if delivery_task.team_list: p.team = delivery_task.team_list[0] p.weight = delivery_task.weight p.returned_weight = delivery_task.returned_weight if not delivery_task.quantity: delivery_task.quantity = sum(store_bill.quantity for store_bill in delivery_task.store_bill_list) p.quantity = delivery_task.quantity if delivery_task.sub_order_list: sb = delivery_task.sub_order_list[0] p.unit = sb.unit p.spec = sb.spec p.type = sb.type do_commit(p)
def update(self, **kwargs): """ update scalar attributes of unload task in database only **weight** and **product_id** allowed """ if kwargs.get("weight"): self.model.weight = kwargs["weight"] if kwargs.get("product_id"): try: self.model.product = models.Product.query.filter( models.Product.id == kwargs["product_id"]).one() except NoResultFound: raise ValueError(u"无此产品%s" % kwargs["product_id"]) if kwargs.get("customer"): self.model.customer = kwargs["customer"] do_commit(self.model)
def _(step, plate_name, us): plate_ = do_commit(models.Plate(name=plate_name)) with app.test_request_context(): with app.test_client() as c: rv = c.post(u"/cargo/unload-session/%d" % us.id, data={"plate_": plate_name}) assert 302 == rv.status_code
def post_product(data): count = 0 for k, v in data.items(): product_type = models.ProductType.query.filter( models.ProductType.MSSQL_ID == int(k)).one() for product in v: try: models.Product.query.filter( models.Product.name == product["name"]).filter( models.Product.product_type == product_type).one() except NoResultFound: do_commit( models.Product(product["name"], product_type, MSSQL_ID=product["id"])) count += 1 return u"成功添加%d条产品信息" % count
def side_effect(self, **kwargs): self.sm.obj.set_status(constants.work_command.STATUS_DISPATCHING) if self.last_status == constants.work_command.STATUS_LOCKED: # 根据车间主任之前填写的工序后重量/数量,将原有工单的重量修正后 # 返回 old_wc = self.sm.obj old_wc.org_weight -= kwargs["weight"] if old_wc.org_weight <= 0: # 至少保证为1, 这同时也意味着原有工单的重量不准确,所以不能 # 进行回收 old_wc.org_weight = 1 processed_weight = kwargs["weight"] if old_wc.sub_order.order_type == constants.EXTRA_ORDER_TYPE: old_wc.org_cnt -= kwargs["quantity"] processed_quantity = kwargs["quantity"] else: old_wc.org_cnt = old_wc.org_weight processed_quantity = processed_weight if old_wc.org_cnt <= 0: # 至少保证为1, 这同时也意味着原有工单的数量不准确,所以不能 # 进行回收 old_wc.org_cnt = 1 if processed_weight and processed_quantity: new_wc = models.WorkCommand( sub_order=old_wc.sub_order, org_weight=processed_weight, procedure=old_wc.procedure, urgent=old_wc.urgent, status=constants.work_command.STATUS_QUALITY_INSPECTING, department=old_wc.department, processed_weight=processed_weight, team=old_wc.team, previous_procedure=old_wc.previous_procedure, tag=old_wc.tag, tech_req=old_wc.tech_req, org_cnt=processed_quantity, processed_cnt=processed_quantity, pic_path=old_wc.pic_path, handle_type=old_wc.handle_type, previous_work_command=old_wc) do_commit(new_wc) self.sm.obj.department = None self.sm.obj.team = None
def side_effect(self, **kwargs): self.sm.obj.set_status(constants.work_command.STATUS_DISPATCHING) if self.last_status == constants.work_command.STATUS_LOCKED: # 根据车间主任之前填写的工序后重量/数量,将原有工单的重量修正后 # 返回 old_wc = self.sm.obj old_wc.org_weight -= kwargs["weight"] if old_wc.org_weight <= 0: # 至少保证为1, 这同时也意味着原有工单的重量不准确,所以不能 # 进行回收 old_wc.org_weight = 1 processed_weight = kwargs["weight"] if old_wc.sub_order.order_type == constants.EXTRA_ORDER_TYPE: old_wc.org_cnt -= kwargs["quantity"] processed_quantity = kwargs["quantity"] else: old_wc.org_cnt = old_wc.org_weight processed_quantity = processed_weight if old_wc.org_cnt <= 0: # 至少保证为1, 这同时也意味着原有工单的数量不准确,所以不能 # 进行回收 old_wc.org_cnt = 1 if processed_weight and processed_quantity: new_wc = models.WorkCommand(sub_order=old_wc.sub_order, org_weight=processed_weight, procedure=old_wc.procedure, urgent=old_wc.urgent, status=constants.work_command.STATUS_QUALITY_INSPECTING, department=old_wc.department, processed_weight=processed_weight, team=old_wc.team, previous_procedure=old_wc.previous_procedure, tag=old_wc.tag, tech_req=old_wc.tech_req, org_cnt=processed_quantity, processed_cnt=processed_quantity, pic_path=old_wc.pic_path, handle_type=old_wc.handle_type, previous_work_command=old_wc) do_commit(new_wc) self.sm.obj.department = None self.sm.obj.team = None
def upgrade(): from lite_mms.models import ConsignmentProduct op.create_table(ConsignmentProduct.__tablename__, Column('id', Integer(), primary_key=True, nullable=False), Column('consignment_id', Integer(), ForeignKey('TB_CONSIGNMENT.id'), nullable=False), Column('product_id', Integer(), ForeignKey('TB_PRODUCT.id'), nullable=False), Column('delivery_task_id', Integer(), ForeignKey('TB_DELIVERY_TASK.id'), nullable=False), Column('weight', Integer()), Column('quantity', Integer()), Column('unit', String(length=16), default=''), Column('spec', String(length=64)), Column('type', String(length=64)), Column('returned_weight', Integer()), Column('team_id', Integer(), ForeignKey('TB_TEAM.id'), nullable=True)) from lite_mms.utilities import do_commit from lite_mms.apis.delivery import get_delivery_session_list delivery_session_list = get_delivery_session_list()[0] for delivery_session in delivery_session_list: for consignment in delivery_session.consignment_list: for t in delivery_session.delivery_task_list: if t.customer: if t.customer.id == consignment.customer_id: p = ConsignmentProduct(t.product, t, consignment) if t.team_list: p.team = t.team_list[0] p.weight = t.weight p.returned_weight = t.returned_weight if not t.quantity: t.quantity = sum( store_bill.quantity for store_bill in t.store_bill_list) p.quantity = t.quantity sb = t.sub_order_list.next() p.unit = sb.unit p.spec = sb.spec p.type = sb.type do_commit((p, t)) else: do_commit(t, "delete")
def add_product_entry(self, delivery_task): p = models.ConsignmentProduct(delivery_task.product, delivery_task, self) if delivery_task.team_list: p.team = delivery_task.team_list[0] p.weight = delivery_task.weight p.returned_weight = delivery_task.returned_weight if not delivery_task.quantity: delivery_task.quantity = sum( store_bill.quantity for store_bill in delivery_task.store_bill_list) p.quantity = delivery_task.quantity if delivery_task.sub_order_list: sb = delivery_task.sub_order_list[0] p.unit = sb.unit p.spec = sb.spec p.type = sb.type do_commit(p)
def create_or_update_consignment(customer_id, delivery_session_id, pay_in_cash): try: cn = ConsignmentWrapper( models.Consignment.query.filter( models.Consignment.customer_id == customer_id).filter( models.Consignment.delivery_session_id == delivery_session_id).one()) cn.pay_in_cash = pay_in_cash if cn.stale: cn.add_product_entries() cn.stale = False do_commit(cn) return cn except NoResultFound: return new_consignment(customer_id, delivery_session_id, pay_in_cash=pay_in_cash)
def _(step, customer, harbor, plate, product): us = do_commit(models.UnloadSession(plate_=plate, gross_weight=123123123)) from lite_mms.constants.cargo import STATUS_CLOSED us.status = STATUS_CLOSED import datetime us.finish_time = datetime.datetime.now() do_commit(us) ut = do_commit( models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False)) return us
def update(cls, id, **kwargs): consignment = ConsignmentWrapper.get_consignment(id) if consignment.MSSQL_ID: raise ValueError(u"已导入原系统的发货单不能再修改") for k, v in kwargs.items(): if hasattr(consignment, k): setattr(consignment, k, v) if k == "pay_in_cash" and v and not consignment.pay_in_cash: consignment.add_todo() return ConsignmentWrapper(do_commit(consignment))
def delete(self): us = self.unload_session do_commit(self.model, "delete") from lite_mms.portal.cargo.fsm import fsm fsm.reset_obj(us) from flask.ext.login import current_user from lite_mms.basemain import timeline_logger timeline_logger.info(u"删除了卸货任务%d" % self.id, extra={"obj": self.unload_session.model, "obj_pk": self.unload_session.id, "action": u"删除卸货任务", "actor": current_user}) fsm.next(constants.cargo.ACT_WEIGHT, current_user) from lite_mms.apis import todo # delete todo.remove_todo(todo.WEIGH_UNLOAD_TASK, self.id) return True
def delete(self): ds = self.delivery_session do_commit(self.model, "delete") from lite_mms.portal.delivery.fsm import fsm fsm.reset_obj(ds) from flask.ext.login import current_user from lite_mms.basemain import timeline_logger timeline_logger.info(u"删除了发货任务%d" % self.id, extra={"obj": self.delivery_session.model, "obj_pk": self.delivery_session.id, "action": u"删除发货任务", "actor": current_user}) fsm.next(constants.delivery.ACT_WEIGHT, current_user) from lite_mms.apis import todo # delete todo todo.remove_todo(todo.WEIGH_DELIVERY_TASK, self.id) return True
def new_unload_task(session_id, harbor, customer_id, creator_id, pic_path, is_last=False): """ 持久化创建一个unload task :return: 若创建成功,返回创建的unload task :rtype: UnloadTaskWrapper :raise: * ValueError - 如果参数发生错误 """ try: harbor = models.Harbor.query.filter(models.Harbor.name == harbor).one() except NoResultFound: raise ValueError(u"没有该装卸点" + harbor) try: creator = models.User.query.filter(models.User.id == creator_id).one() except NoResultFound: raise ValueError(_(u"没有该用户(%d)" % int(creator_id))) try: customer = models.Customer.query.filter( models.Customer.id == customer_id).one() except NoResultFound: raise ValueError(_(u"没有该客户(%d)" % int(customer_id))) import lite_mms.apis as apis product = apis.product.get_product(name=constants.DEFAULT_PRODUCT_NAME) if not product: raise ValueError(_(u"没有该产品" + constants.DEFAULT_PRODUCT_NAME)) unload_session = get_unload_session(session_id) if not unload_session: raise ValueError(_(u"没有该卸货会话(%d)" % int(session_id))) if unload_session.finish_time: raise ValueError(u"该卸货会话(%d)已经结束" % int(session_id)) ut = do_commit(models.UnloadTask( unload_session=unload_session.model, harbor=harbor, customer=customer, creator=creator, pic_path=pic_path, product=product, is_last=is_last)) from lite_mms.apis.todo import new_todo, WEIGH_UNLOAD_TASK from lite_mms.apis.auth import get_user_list for to in get_user_list(constants.groups.CARGO_CLERK): new_todo(to, WEIGH_UNLOAD_TASK, ut) return UnloadTaskWrapper(ut)
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))
def _(step, customer_name, customer, harbor, product, us, is_last): from lite_mms.constants.cargo import STATUS_WEIGHING us.status = STATUS_WEIGHING return do_commit( models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=is_last))
def delete(self): ds = self.delivery_session do_commit(self.model, "delete") from lite_mms.portal.delivery.fsm import fsm fsm.reset_obj(ds) from flask.ext.login import current_user from lite_mms.basemain import timeline_logger timeline_logger.info(u"删除了发货任务%d" % self.id, extra={ "obj": self.delivery_session.model, "obj_pk": self.delivery_session.id, "action": u"删除发货任务", "actor": current_user }) fsm.next(constants.delivery.ACT_WEIGHT, current_user) from lite_mms.apis import todo # delete todo todo.remove_todo(todo.WEIGH_DELIVERY_TASK, self.id) return True
def _(step, customer, harbor): plate = do_commit(models.Plate(name=generate(5))) unload_session = do_commit(models.UnloadSession(plate_=plate, gross_weight=50000)) product_type = do_commit(models.ProductType(name=generate(5))) product = do_commit(models.Product(name=generate(5), product_type=product_type)) procedure = do_commit(models.Procedure(name=generate(5))) goods_receipt = do_commit(models.GoodsReceipt(customer=customer, unload_session=unload_session)) for i in xrange(3): goods_receipt_entry = do_commit( models.GoodsReceiptEntry(goods_receipt=goods_receipt, product=product, weight=5000, harbor=harbor)) return goods_receipt
def _(step, customer, harbor, product): from random import choice import string plate_ = do_commit( models.Plate( name=u"浙%s %s%s%s%s%s" % (choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase), choice(string.ascii_lowercase)))) us = do_commit(models.UnloadSession(plate_=plate_, gross_weight=100000)) from lite_mms.constants.cargo import STATUS_WEIGHING ut = do_commit( models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False)) us.status = STATUS_WEIGHING return us
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))
def new_todo(whom, action, obj=None, msg="", sender=None, **kwargs): """ 告诉"whom"对"obj"执行"action" :param whom: who should be responsible for this todo :type whom: models.User :param unicode action: what should do :param obj: action should be performed upon which :param msg: supplementary message :param sender: who send this message, if not specified, we regard SYSTEM send this todo :Param kwargs: supplementary information """ todo = do_commit( todo_factory.render(whom, action, obj, msg, sender, **kwargs)) notify(whom.id, todo.id)
def _(step, us, customer, harbor, product): from lite_mms.constants.cargo import STATUS_WEIGHING, STATUS_LOADING us.status = STATUS_WEIGHING ut = do_commit( models.UnloadTask(customer=customer, unload_session=us, harbor=harbor, creator=None, pic_path="", product=product, is_last=False, weight=5000)) us.status = STATUS_LOADING return ut
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(self, **kwargs): if kwargs.get("weight"): self.weight = kwargs['weight'] total_org_weight = float( sum([sb.weight for sb in self.store_bill_list])) for sb in self.store_bill_list: sb.model.weight = int( round(self.weight * sb.weight / total_org_weight)) from lite_mms import constants if sb.sub_order.order_type == constants.STANDARD_ORDER_TYPE: sb.model.quantity = sb.model.weight if self.consignment: self.consignment.staled() elif kwargs.get("returned_weight"): self.model.returned_weight = kwargs["returned_weight"] if self.consignment: self.consignment.staled() # 这也说明,若是计件类型的仓单,数量不会根据称重进行调整 elif kwargs.get("is_last"): self.model.is_last = kwargs["is_last"] do_commit(self.model) return self