Esempio n. 1
0
class StuffdrawpaperModule(QWidget, Ui_Form):
    def __init__(self, autoid, parent=None):
        # autoid:领料单在stuffdrawpaper中的autoid
        # kind: 领料单的类型与原料对应
        super(StuffdrawpaperModule, self).__init__(parent)
        self.autoid = autoid
        self.ori_detail = object
        self.new_detail = {}
        self.SC = StuffController()
        self.setupUi(self)
        self.pushButton_apply.setVisible(False)
        self.get_stuffdrawpaper()

    # 获取领料单的状态
    def get_stuffdrawpaper(self):
        res = self.SC.get_stuffdrawpaper(autoid=self.autoid)
        if len(res) == 1:
            self.ori_detail = res[0]

            self.label_dept.setText(
                self.ori_detail.deptid + ' ' + self.ori_detail.deptname)
            if self.ori_detail.status == 0:
                self.label_status.setText("未提交")
                self.pushButton_apply.setVisible(True)
                self.pushButton_apply.setText("提交领料")
                self.label_charger.setText('')
                self.label_provider.setText('')
                self.dateEdit_applytime.setVisible(False)
                self.dateEdit_drawtime.setVisible(False)
            elif self.ori_detail.status == 1:
                self.label_status.setText("已提交")
                self.pushButton_apply.setText("取消领料")
                self.label_charger.setText(
                    self.ori_detail.chargerid + ' ' + self.ori_detail.chargername)
                self.label_provider.setText('')
                self.dateEdit_applytime.setDate(
                    self.ori_detail.applydate)
                self.dateEdit_applytime.setVisible(True)
                self.dateEdit_drawtime.setVisible(False)
            elif self.ori_detail.status == 2:
                self.label_status.setText("已完成")
                self.label_charger.setText(
                    self.ori_detail.chargerid + ' ' + self.ori_detail.chargername)
                self.label_provider.setText(
                    self.ori_detail.providerid + ' ' + self.ori_detail.providername)
                self.dateEdit_applytime.setDate(
                    self.ori_detail.applydate)
                self.dateEdit_drawtime.setDate(self.ori_detail.drawdate)
                self.get_stufflist()

    # 获取已经领取了的物料
    def get_stufflist(self):
        values_tupe = (
            "autoid", "lrid", "stuffid", "stuffname", "batchno", "spec",
            "package", "presamount", "pracamount", "drawamount", "content",
            "cunit", "water", "impurity", "rdensity", "presunit", "pracunit",
            "drawunit"
        )
        key_dict = {'sdpid': self.autoid}
        res = self.SC.get_prodstuff(0, *values_tupe, **key_dict)
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
                qtreeitem.setText(0, str(item['autoid']))  # autoid
                qtreeitem.setText(1, str(item['lrid']))  # lrid
                qtreeitem.setText(2, item['stuffid'] + ' ' + item['stuffname'])  # 物料
                qtreeitem.setText(3, item['batchno'])  # 进厂批号
                qtreeitem.setText(4, item['spec'])  # 含量规格
                qtreeitem.setText(5, item['package'])  # 包装规格
                qtreeitem.setText(6, str(item['presamount']) + item['presunit'])  # 计划量
                qtreeitem.setText(7, str(item['pracamount']) + item['pracunit'])  # 实际量
                qtreeitem.setText(8, str(item['drawamount']) + item['drawunit'])  # 领取量
                qtreeitem.setText(9, str(item['content']) + item['cunit'])  # 含量/效价
                qtreeitem.setText(10, str(item['water']) + '%')  # 水分
                qtreeitem.setText(11, str(item['impurity']))  # 相对密度
                qtreeitem.setText(12, str(item['rdensity']))  # 杂质

            self.treeWidget_stufflist.hideColumn(0)
            self.treeWidget_stufflist.hideColumn(1)
            for i in range(2, 11):
                self.treeWidget_stufflist.resizeColumnToContents(i)

    # 提交领料
    @pyqtSlot()
    def on_pushButton_apply_clicked(self):
        if self.ori_detail.status == 0:
            self.new_detail['status'] = 1
            self.new_detail['chargerid'] = user.user_id
            self.new_detail['chargername'] = user.user_name
            self.new_detail['applydate'] = user.now_date
            # print(self.new_detail)
            res = self.SC.update_stuffdrawpaper(autoid=self.autoid,
                                                **self.new_detail)

        elif self.ori_detail.status == 1:
            self.new_detail['status'] = 0
            self.new_detail['chargerid'] = ''
            self.new_detail['chargername'] = ''
            self.new_detail['applydate'] = None
            res = self.SC.update_stuffdrawpaper(autoid=self.autoid,
                                                **self.new_detail)
        if res:
            self.get_stuffdrawpaper()
Esempio n. 2
0
class WarehouseController(object):
    def __init__(self):
        self.SC = StuffController()
        self.SLC = SaleController()
        self.SP = SupplyerController()
        self.WM = WarehouseModel()
        self.WC = WorkshopController()
        self.PC = ProductController()

    def get_stuffdrawpaper(self, *args, **kwargs):
        return self.SC.get_stuffdrawpaper(*args, **kwargs)
        """if len(res):
            ppid_list = list()
            for item in res:
                ppid_list.append(item.ppid)
            value_tuple = (
                'autoid', 'prodid', 'prodname', 'spec', 'package', 'batchno')
            prod_info_tuple = self.WM.get_producingplan(*value_tuple,
                                                        autoid__in=set(
                                                            ppid_list))
            for item in res:
                for it in prod_info_tuple:
                    if item.ppid == it[0]:
                        item.prod = it[1] + ' ' + it[2]
                        item.spec = it[3]
                        item.package = it[4]
                        item.batchno = it[5]
            return res
        else:
            return []"""

    def get_stuffrepository(self, display_flag=False, *args, **kwargs):
        return self.WM.get_stuffrepository(display_flag, *args, **kwargs)
        """res = self.WM.get_stuffrepository(flag, *args, **kwargs)
        supid_list = []
        if len(res):
            for item in res:
                supid_list.append(item['supid'])
            supplyers = self.SP.get_supply(('supid', 'supname'), supid__in=set(supid_list))
            for item in res:
                item['supname'] = ''
                for supplyer in supplyers:
                    if item['supid'] == supplyer[0]:
                        item['supname'] = supplyer[1]
                        break
        return res
        """

    def update_stuffrepository(self, autoid=None, *args, **kwargs):
        return WarehouseModel.update_stuffrepository(autoid, *args, **kwargs)

    def update_stuffrepository_amount(self, ppid, *args, **kwargs):
        return WarehouseModel.update_stuffrepository_amount(
            ppid, *args, **kwargs)

    def get_productputoutpaper(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_productputoutpaper(display_flag, *args,
                                                     **kwargs)

    def update_productputoutpaper(self, autoid=None, *args, **kwargs):
        return WarehouseModel.update_productputoutpaper(
            autoid, *args, **kwargs)

    def delete_productputoutpaper(self, autoid=None, *args, **kwargs):
        return WarehouseModel.delete_productputoutpaper(
            autoid, *args, **kwargs)

    def get_prodwithdrawnote(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_prodwithdrawnote(display_flag, *args,
                                                   **kwargs)

    def update_prodwithdrawnote(self, autoid, *args, **kwargs):
        return WarehouseModel.update_prodwithdrawnote(autoid, *args, **kwargs)

    def delete_prodwithdrawnote(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_prodwithdrawnote(autoid, *args, **kwargs)

    def get_ppopqrcode(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_ppopqrcode(display_flag, *args, **kwargs)

    def update_ppopqrcode(self, autoid, *args, **kwargs):
        return WarehouseModel.update_ppopqrcode(autoid, *args, **kwargs)

    def delete_ppopqrcode(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_ppopqrcode(autoid, *args, **kwargs)

    def get_pwqrcode(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_pwqrcode(display_flag, *args, **kwargs)

    def update_pwqrcode(self, autoid, *args, **kwargs):
        return WarehouseModel.update_pwqrcode(autoid, *args, **kwargs)

    def delete_pwqrcode(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_pwqrcode(autoid, *args, **kwargs)

    def get_stuffcheckin(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_stuffcheckin(display_flag, *args, **kwargs)

    def update_stuffcheckin(self, autoid, *args, **kwargs):
        return WarehouseModel.update_stuffcheckin(autoid, *args, **kwargs)

    def new_stuffcheckin(self, ppid, *args, **kwargs):
        detail = dict()
        key_dict = {'ppid': ppid}
        stuff_query = self.SP.get_purchstuff(False, *VALUES_TUPLE_PPLIST,
                                             **key_dict)
        if not len(stuff_query):
            return
        stuff_list = list(stuff_query)

        with transaction.atomic():
            p1 = transaction.savepoint()
            res = WarehouseModel.update_stuffcheckin(None, *args, **kwargs)

            for item in stuff_list:
                if item['amount'] - item['arrivedamount'] <= 0:
                    continue
                detail['paperno'] = res.paperno
                detail['papertype'] = 0
                detail['makedate'] = user.now_date
                detail['expireddate'] = user.now_date + datetime.timedelta(
                    days=item['expireddays'])
                detail['checkindate'] = user.now_date
                detail['amount'] = item['amount'] - item['arrivedamount']
                detail['piamount'] = item['amount'] - item['arrivedamount']
                detail['supid'] = kwargs['supid']
                detail['supname'] = kwargs['supname']
                del item['amount']
                del item['arrivedamount']
                del item['expireddays']
                detail.update(item)
                WarehouseModel.update_stuffcheckinlist(None, **detail)

    def delete_stuffcheckin(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_stuffcheckin(autoid, *args, **kwargs)

    def get_stuffcheckinlist(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_stuffcheckinlist(display_flag, *args,
                                                   **kwargs)

    def update_stuffcheckinlist(self, autoid, *args, **kwargs):
        return WarehouseModel.update_stuffcheckinlist(autoid, *args, **kwargs)

    def delete_stuffcheckinlist(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_stuffcheckinlist(autoid, *args, **kwargs)

    def get_productrepository(self, display_flag=False, *args, **kwargs):
        return WarehouseModel.get_productrepository(display_flag, *args,
                                                    **kwargs)

    def update_productrepository(self, autoid, *args, **kwargs):
        return WarehouseModel.update_productrepository(autoid, *args, **kwargs)

    def delete_productrepository(self, autoid, *args, **kwargs):
        return WarehouseModel.delete_productrepository(autoid, *args, **kwargs)

    def find_prodqrcode(self, qrcode):
        """ 产品二维码中是否找到输入的二维码(qrcode)
        返回4个参数
        第一个参数
            0: 找到二维码且(全部)未使用
            1: 找到二维码但(全部)已被使用
            2: 找到二维码但(部分)已被使用
            3: 找不到二维码
        第二个参数
            二维码级别
        第三个参数
            二维码对应的数量
        第四个参数
            二维码所在的ppid,选择结果集中的第一个ppid
        第五个二维码
            二维码所在的batchno,选择结果集的第一个batchno
        """
        key_dict_0 = {'qrcode0': qrcode}
        key_dict_1 = {'qrcode1': qrcode}
        key_dict_2 = {'qrcode2': qrcode}
        key_dict_3 = {'qrcode3': qrcode}
        res = None
        i = 0
        for i in range(0, 4):
            res = self.WC.get_prodqrcode(False, *VALUES_TUPLE_PRODQRCODE,
                                         **locals()['key_dict_' + str(i)])
            if len(res):
                break
        if not len(res):
            return 3, i, 0, 0, ''
        res_dist = res.distinct()
        sum = len(res)
        amount = self.sum_to_amount(sum, i, res_dist[0]['ppid'])

        if len(res_dist) == 2:

            return 2, i, amount, res_dist[0]['ppid'], res_dist[0]['batchno']
        elif len(res_dist) == 1:
            item = res_dist[0]
            if item['used'] == 0:
                return 0, i, amount, item['ppid'], item['batchno']
            else:
                return 1, i, amount, item['ppid'], item['batchno']
        else:
            return False

    def sum_to_amount(self, sum, i, ppid):
        """把二维码次数转位数量
        :parameter
            sum:二维码的数量
            i:第几级二维码
            ppid: 对应的批生产记录
        :return
            amount: 转换后的数量
        首先要获取ppid对应记录的扫码比例
        如果是0则 则amount=sum,否则amount=sum*没有扫码的级别数量
        """
        key_dict_pp = {'autoid': ppid}
        res = self.PC.get_producingplan(False, *VALUES_TUPLE_PP, **key_dict_pp)
        if not len(res):
            return 1
        qrtype = res[0]['qrtype']
        amount_list = (res[0]['bpamount'], res[0]['mpamount'],
                       res[0]['spamount'])
        if qrtype == 1:
            return sum
        for key, value in enumerate('{:04b}'.format(qrtype)[::-1]):
            if value == '1':
                break
            elif value == '0':
                sum *= amount_list[2 - key]
        return sum

    def add_ppopqrocde(self, flag, qrcode, detail):
        with transaction.atomic():
            p1 = transaction.savepoint()

            WarehouseModel.update_ppopqrcode(**detail)
            key_dict = {globals()['QRCODE_KIND'][flag]: qrcode}
            values = {'used': 1}
            self.WC.update_prodqrcode(key_dict, **values)

    def drop_ppopqrocde(self, flag, qrcode, autoid=None, **kwargs):
        with transaction.atomic():
            p1 = transaction.savepoint()

            WarehouseModel.delete_ppopqrcode(autoid, **kwargs)
            key_dict = {globals()['QRCODE_KIND'][flag]: qrcode}
            values = {'used': 0}
            self.WC.update_prodqrcode(key_dict, **values)

    def apply_productputoutpaper(self, autoid, snid=None, *args, **kwargs):
        with transaction.atomic():
            p1 = transaction.savepoint()
            WarehouseModel.update_productputoutpaper(autoid, *args, **kwargs)
            if snid is not None:
                key_dict_sn = {
                    'status': 3,
                    'deliverid': user.user_id,
                    'delivername': user.user_name
                }
                self.SLC.update_salenotes(snid, **key_dict_sn)
            key_dict = {'ppopid': autoid}
            qrcode_list = WarehouseModel.get_ppopqrcode(
                False, *VALUES_TUPLE_PPOPRCODE, **key_dict).order_by('ppid')
            no_enough_list = []
            # 大中小包装得数量
            for item in qrcode_list:
                kind = item['kind']
                amount = item['amount']
                ppid = item['ppid']

                if kind == 0:
                    key_dict_rep = {'pisource': 0, 'ppid': ppid}
                    rep_list = WarehouseModel.get_productrepository(
                        **key_dict_rep)
                    for rep_item in rep_list:
                        if rep_item.stockamount - amount >= 0:
                            rep_item.stockamount -= amount
                            amount = 0
                            rep_item.save()
                            break
                        else:
                            amount -= rep_item.stockamount
                            rep_item.stockamount = 0
                            rep_item.save()
                    if amount > 0:
                        no_enough_list.append((0, ppid))

                elif kind == 1:
                    key_dict_rep = {'pisource': 1, 'ppid': ppid}
                    # 优先比较零头的数量
                    rep_list = WarehouseModel.get_productrepository(
                        **key_dict_rep)
                    for rep_item in rep_list:
                        if rep_item.stockamount - amount >= 0:
                            rep_item.stockamount -= amount
                            amount = 0
                            rep_item.save()
                            break
                        else:
                            amount -= rep_item.stockamount
                            rep_item.stockamount = 0
                            rep_item.save()
                    if amount > 0:
                        key_dict_rep = {'pisource': 2, 'hxid': ppid}
                        # 优先比较零头的数量
                        rep_list = WarehouseModel.get_productrepository(
                            **key_dict_rep)
                        for rep_item in rep_list:
                            # 剩余数量和合箱剩余数量都是足够
                            if rep_item.stockamount - amount >= 0 and \
                                    rep_item.hxstockamount - amount >= 0:

                                rep_item.stockamount -= amount
                                rep_item.hxstockamount -= amount
                                amount = 0
                                rep_item.save()
                                break
                            else:
                                amount -= rep_item.hxstockamount
                                rep_item.hxstockamount = 0
                                rep_item.save()
                        if amount > 0:
                            no_enough_list.append((1, ppid))
                elif kind == 2:
                    key_dict_rep = {'pisource': 2, 'ppid': ppid}
                    rep_list = WarehouseModel.get_productrepository(
                        **key_dict_rep)
                    for rep_item in rep_list:
                        # 剩余总数-合箱数量=本批的数量
                        if rep_item.stockamount - rep_item.hxstockamount - \
                                amount >= 0:
                            rep_item.stockamount -= amount
                            amount = 0
                            rep_item.save()
                            break
                        else:
                            amount -= (rep_item.stockamount - \
                                      rep_item.hxstockamount)
                            rep_item.stockamount = rep_item.hxstockamount
                            rep_item.save()
                    if amount > 0:
                        no_enough_list.append((2, ppid))

            if len(no_enough_list):
                transaction.savepoint_rollback(p1)
                return "no enough", no_enough_list
            else:
                return 'OK'

    def stuffreturn(self, autoid=0, backamount_list=[], *args, **kwargs):
        key_dict = {'autoid': 0}
        with transaction.atomic():
            p1 = transaction.savepoint()
            self.SC.update_stuffdrawpaper(autoid, *args, **kwargs)
            for item in backamount_list:
                id = item[0]
                backamount = item[1]
                key_dict['autoid'] = id
                sr_list = WarehouseModel.get_stuffrepository(False, **key_dict)
                if not len(sr_list):
                    continue
                sr_item = sr_list[0]
                sr_item.amount += backamount
                sr_item.save()

    def get_data(self, table_num: int, display_flag=False, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "查询" + TABLE_SET[table_num][1]
        return WarehouseModel.get_data(table_str, err_msg, display_flag, *args,
                                       **kwargs)

    def update_data(self, table_num: int, condition={}, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "更新" + TABLE_SET[table_num][1]
        return WarehouseModel.update_data(table_str, err_msg, condition, *args,
                                          **kwargs)

    def delete_data(self, table_num: int, condition={}, *args, **kwargs):
        table_str = TABLE_SET[table_num][0]
        err_msg = "删除" + TABLE_SET[table_num][1]
        return WarehouseModel.delete_data(table_str, err_msg, condition, *args,
                                          **kwargs)
Esempio n. 3
0
class StuffReturnPaperModule(QWidget, Ui_Form):
    def __init__(self, autoid, parent=None):
        # autoid:领料单在stuffdrawpaper中的autoid
        super(StuffReturnPaperModule, self).__init__(parent)
        self.autoid = autoid
        self.ori_detail = dict()
        self.new_detail = dict()
        self.SC = StuffController()
        self.setupUi(self)
        self.pushButton_apply.setVisible(False)
        self.pushButton_cancel.setVisible(False)

        self.get_stuffdrawpaper()
        self.get_stufflist()

    # 获取领料单的状态
    def get_stuffdrawpaper(self):
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_stuffdrawpaper(False, *VALUES_TUPLE_pAPER,
                                         **key_dict)
        if len(res) == 1:
            self.ori_detail = res[0]

            self.label_dept.setText(self.ori_detail['deptid'] + ' ' +
                                    self.ori_detail['deptname'])
            if self.ori_detail['wdstatus'] == 0:
                self.label_status.setText("未提交")
                self.pushButton_apply.setVisible(True)
                self.pushButton_cancel.setVisible(False)
                self.label_charger.setText('')
                # self.label_provider.setText('')
                self.dateEdit_applytime.setVisible(False)
                self.dateEdit_receivetime.setVisible(False)
            elif self.ori_detail['wdstatus'] == 1:
                self.label_status.setText("已提交")
                self.pushButton_apply.setVisible(False)
                self.pushButton_cancel.setVisible(True)
                self.label_charger.setText(self.ori_detail['wdchargerid'] +
                                           ' ' +
                                           self.ori_detail['wdchargername'])
                self.label_receiver.setText('')
                self.dateEdit_applytime.setDate(self.ori_detail['wddate'])
                self.dateEdit_applytime.setVisible(True)
                self.dateEdit_receivetime.setVisible(False)
            elif self.ori_detail['wdstatus'] == 2:
                self.pushButton_apply.setVisible(False)
                self.pushButton_cancel.setVisible(False)
                self.label_status.setText("已完成")
                self.label_charger.setText(self.ori_detail['wdchargerid'] +
                                           ' ' +
                                           self.ori_detail['wdchargername'])
                self.label_receiver.setText(self.ori_detail['wddrawerid'] +
                                            ' ' +
                                            self.ori_detail['wddrawername'])
                self.dateEdit_applytime.setDate(self.ori_detail['wddate'])
                self.dateEdit_receivetime.setDate(
                    self.ori_detail['wddrawdate'])

    # 获取已经领取了的物料
    def get_stufflist(self):
        self.treeWidget_stufflist.clear()
        self.treeWidget_stufflist.hideColumn(0)
        key_dict = {'sdpid': self.autoid}
        if self.label_status.text() == "已完成":
            key_dict['backamount__gt'] = 0
        res = self.SC.get_prodstuff(False, *VALUES_TUPLE_STUFF, **key_dict)
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
                qtreeitem.setText(0, str(item['autoid']))  # autoid
                qtreeitem.setText(1, item['stuffid'] + ' ' +
                                  item['stuffname'])  # 物料
                qtreeitem.setText(2, item['batchno'])  # 进厂批号
                qtreeitem.setText(3, item['spec'])  # 含量规格
                qtreeitem.setText(4, item['package'])  # 包装规格
                qtreeitem.setText(5,
                                  to_str(item['presamount']) +
                                  item['presunit'])  # 计划量
                qtreeitem.setText(6,
                                  to_str(item['pracamount']) +
                                  item['pracunit'])  # 实际量
                qtreeitem.setText(7,
                                  to_str(item['drawamount']) +
                                  item['drawunit'])  # 领取量
                qtreeitem.setText(8,
                                  to_str(item['restamount']) +
                                  item['drawunit'])  # 剩余量
                qtreeitem.setText(9,
                                  to_str(item['backamount']) +
                                  item['drawunit'])  # 退库量量
                qtreeitem.setText(10, item['wdid'] + item['wdname'])

            for i in range(1, 11):
                self.treeWidget_stufflist.resizeColumnToContents(i)

    # 提交领料
    @pyqtSlot()
    def on_pushButton_apply_clicked(self):
        if self.ori_detail['wdstatus'] != 0:
            return
        self.new_detail['wdstatus'] = 1
        self.new_detail['wdchargerid'] = user.user_id
        self.new_detail['wdchargername'] = user.user_name
        self.new_detail['wddate'] = user.now_date
        # print(self.new_detail)
        self.SC.update_stuffdrawpaper(autoid=self.autoid, **self.new_detail)
        self.get_stuffdrawpaper()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        if self.ori_detail['wdstatus'] != 1:
            return
        self.new_detail['wdstatus'] = 0
        self.new_detail['wdchargerid'] = ''
        self.new_detail['wdchargername'] = ''
        self.new_detail['wddate'] = None
        self.SC.update_stuffdrawpaper(autoid=self.autoid, **self.new_detail)
        self.get_stuffdrawpaper()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_stufflist_itemDoubleClicked(self, q_treeitem, p_int):
        if self.label_status.text() != "未提交":
            return
        id = int(q_treeitem.text(0))
        detail = EditStuffReturnDetailModule(id, self)
        detail.accepted.connect(self.get_stufflist)
        detail.show()
class StuffReturnInModule(QDialog, Ui_Dialog):
    def __init__(self, autoid, parent=None):
        # autoid:退料单在stuffdrawpaper中的autoid
        super(StuffReturnInModule, self).__init__(parent)
        self.autoid = autoid
        self.ori_detail = dict()
        self.new_detail = dict()
        self.stuff_backamount_list = []
        self.SC = StuffController()
        self.WC = WarehouseController()
        self.setupUi(self)
        self.pushButton_apply.setVisible(False)
        self.pushButton_cancel.setVisible(False)

        self.get_stuffdrawpaper()
        self.get_stufflist()

    # 获取领料单的状态
    def get_stuffdrawpaper(self):
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_stuffdrawpaper(False, *VALUES_TUPLE_PAPER,
                                         **key_dict)
        if not len(res):
            return

        self.ori_detail = res[0]

        self.label_dept.setText(self.ori_detail['deptid'] + ' ' +
                                self.ori_detail['deptname'])
        if self.ori_detail['wdstatus'] == 0:
            self.label_status.setText("未提交")
            self.pushButton_apply.setVisible(False)
            self.pushButton_cancel.setVisible(False)
            self.label_charger.setText('')
            # self.label_provider.setText('')
            self.dateEdit_applytime.setVisible(False)
            self.dateEdit_receivetime.setVisible(False)
        elif self.ori_detail['wdstatus'] == 1:
            self.label_status.setText("已提交")
            self.pushButton_apply.setVisible(True)
            self.pushButton_cancel.setVisible(True)
            self.label_charger.setText(self.ori_detail['wdchargerid'] + ' ' +
                                       self.ori_detail['wdchargername'])
            self.label_receiver.setText('')
            self.dateEdit_applytime.setDate(self.ori_detail['wddate'])
            self.dateEdit_applytime.setVisible(True)
            self.dateEdit_receivetime.setVisible(False)
        elif self.ori_detail['wdstatus'] == 2:
            self.pushButton_apply.setVisible(False)
            self.pushButton_cancel.setVisible(False)
            self.dateEdit_applytime.setVisible(True)
            self.dateEdit_receivetime.setVisible(True)
            self.label_status.setText("已完成")
            self.label_charger.setText(self.ori_detail['wdchargerid'] + ' ' +
                                       self.ori_detail['wdchargername'])
            self.label_receiver.setText(self.ori_detail['wddrawerid'] + ' ' +
                                        self.ori_detail['wddrawername'])
            self.dateEdit_applytime.setDate(self.ori_detail['wddate'])
            self.dateEdit_receivetime.setDate(self.ori_detail['wddrawdate'])

    # 获取已经领取了的物料
    def get_stufflist(self):
        self.treeWidget_stufflist.clear()
        self.treeWidget_stufflist.hideColumn(0)
        key_dict = {'sdpid': self.autoid, 'backamount__gt': 0}
        res = self.SC.get_prodstuff(False, *VALUES_TUPLE_STUFF, **key_dict)
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
                qtreeitem.setText(0, str(item['autoid']))  # autoid
                qtreeitem.setText(1, str(item['srid']))  # autoid
                qtreeitem.setText(2, item['stuffid'] + ' ' +
                                  item['stuffname'])  # 物料
                qtreeitem.setText(3, item['batchno'])  # 进厂批号
                qtreeitem.setText(4, item['spec'])  # 含量规格
                qtreeitem.setText(5, item['package'])  # 包装规格
                qtreeitem.setText(6,
                                  to_str(item['presamount']) +
                                  item['presunit'])  # 计划量
                qtreeitem.setText(7,
                                  to_str(item['pracamount']) +
                                  item['pracunit'])  # 实际量
                qtreeitem.setText(8,
                                  to_str(item['drawamount']) +
                                  item['drawunit'])  # 领取量
                qtreeitem.setText(9,
                                  to_str(item['restamount']) +
                                  item['drawunit'])  # 剩余量
                qtreeitem.setText(10,
                                  to_str(item['backamount']) +
                                  item['drawunit'])  # 退库量量
                qtreeitem.setText(11, item['wdid'] + item['wdname'])
                self.stuff_backamount_list.append(
                    (item['srid'], item['backamount']))
            for i in range(1, 12):
                self.treeWidget_stufflist.resizeColumnToContents(i)

    # 提交领料
    @pyqtSlot()
    def on_pushButton_apply_clicked(self):
        if self.ori_detail['wdstatus'] != 1:
            return
        self.new_detail['wdstatus'] = 2
        self.new_detail['wddrawerid'] = user.user_id
        self.new_detail['wddrawername'] = user.user_name
        self.new_detail['wddrawdate'] = user.now_date
        self.WC.stuffreturn(self.autoid, self.stuff_backamount_list,
                            **self.new_detail)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        if self.ori_detail['wdstatus'] != 1:
            return
        self.new_detail['wdstatus'] = 0
        self.new_detail['wdchargerid'] = ''
        self.new_detail['wdchargername'] = ''
        self.new_detail['wddate'] = None
        self.SC.update_stuffdrawpaper(autoid=self.autoid, **self.new_detail)
        self.accept()