class EditRegStuffModule(QDialog, Ui_Dialog):
    def __init__(self,
                 spid=None,
                 paperno=None,
                 papertype=0,
                 autoid=None,
                 parent=None):
        super(EditRegStuffModule, self).__init__(parent)
        self.setupUi(self)
        if '28' not in user.powers:
            self.close()
        if user.powers['28'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['28'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.ori_detail = dict()
        self.new_detail = dict()
        self.SC = SupplyerController()
        self.WC = WarehouseController()
        self.SFC = StuffController()

        self.spid = spid
        self.autoid = autoid
        self.paperno = paperno
        self.papertype = papertype

        self.get_detail()
        self.set_amount_validator()
        self.get_producer_list()
        self.get_location_list()

    def get_detail(self):
        if not self.autoid:
            self.toolButton_more.setEnabled(True)
            return
        self.toolButton_more.setEnabled(False)
        key_dict = {'autoid': self.autoid}
        res = self.WC.get_stuffcheckinlist(False, *VALUES_TUPLE_CHECK_IN_LIST,
                                           **key_dict)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.lineEdit_stuff.setText(self.ori_detail['stuffid'] + ' ' +
                                    self.ori_detail['stuffname'])
        self.label_spec.setText(self.ori_detail['spec'])
        self.label_package.setText(self.ori_detail['package'])
        self.lineEdit_amount.setText(str(self.ori_detail['amount']))
        self.label_unit.setText(self.ori_detail['unit'])
        self.lineEdit_batchno.setText(self.ori_detail['batchno'])
        self.lineEdit_mbatchno.setText(self.ori_detail['mbatchno'])
        self.dateEdit_makedate.setDate(self.ori_detail['makedate'])
        self.dateEdit_invaliddate.setDate(self.ori_detail['expireddate'])

    def set_amount_validator(self):
        doubleValitor = QDoubleValidator()
        doubleValitor.setBottom(0)
        doubleValitor.setDecimals(3)
        doubleValitor.setNotation(QDoubleValidator.StandardNotation)
        self.lineEdit_amount.setValidator(doubleValitor)

    def get_location_list(self):
        location_list = self.WC.get_stuffcheckinlist(
            True, *VALUES_TUPLE_LOCATION).distinct()
        if len(location_list):
            self.comboBox_location.addItems(location_list)
        if len(self.ori_detail):
            self.comboBox_location.setCurrentText(self.ori_detail['position'])
        else:
            self.comboBox_location.setCurrentText("")

    def get_producer_list(self, sdid=None):
        if not (self.autoid or sdid):
            return
        if sdid is None:
            stuffid = self.ori_detail['stuffid']
            key_dict_stuff = {'stuffid': stuffid}
            stufffid_list = self.SFC.get_stuffdict(True, *VALUES_TUPLE_SDID,
                                                   **key_dict_stuff)
            if len(stufffid_list):
                sdid = stufffid_list[0]

        if sdid and self.spid:
            key_dict_producer = {'sdid': sdid, 'spid': self.spid}
            producer_list = self.SC.get_stuffsupplyer(True,
                                                      *VALUES_TUPLE_PRODUCER,
                                                      **key_dict_producer)
            if len(producer_list):
                self.comboBox_producer.addItems(producer_list)
            if len(self.ori_detail):
                self.comboBox_producer.setCurrentText(
                    self.ori_detail['producer'])

    @pyqtSlot(str)
    def on_lineEdit_amount_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['amount']:
                self.new_detail['amount'] = p_str
                self.new_detail['piamount'] = p_str
            else:
                try:
                    del self.new_detail['amount']
                    del self.new_detail['piamount']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['amount'] = p_str
            self.new_detail['piamount'] = p_str

    @pyqtSlot(str)
    def on_comboBox_producer_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['producer']:
                self.new_detail['producer'] = p_str
            else:
                try:
                    del self.new_detail['producer']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['producer'] = p_str

    @pyqtSlot(str)
    def on_comboBox_location_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['position']:
                self.new_detail['position'] = p_str
            else:
                try:
                    del self.new_detail['position']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['position'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_batchno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['batchno']:
                self.new_detail['batchno'] = p_str
            else:
                try:
                    del self.new_detail['batchno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['batchno'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_mbatchno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['mbatchno']:
                self.new_detail['mbatchno'] = p_str
            else:
                try:
                    del self.new_detail['mbatchno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['mbatchno'] = p_str

    @pyqtSlot(QDate)
    def on_dateEdit_makedate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['makedate']) is str:
                self.new_detail['makedate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['makedate']):
                self.new_detail['makedate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['makedate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['makedate'] = q_date.toPyDate()

    @pyqtSlot(QDate)
    def on_dateEdit_invaliddate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['expireddate']) is str:
                self.new_detail['expireddate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['expireddate']):
                self.new_detail['expireddate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['expireddate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['expireddate'] = q_date.toPyDate()

    @pyqtSlot()
    def on_toolButton_more_clicked(self):
        detail = SelectstuffModule(self.spid, self)
        detail.selected.connect(self.set_stuff)
        detail.show()

    def set_stuff(self, p_int):

        key_dict = {'autoid': p_int}
        res = self.SFC.get_stuffdict(False, *VALUES_TUPLE_STUFF, **key_dict)

        if not len(res):
            return
        stuff = res[0]
        self.lineEdit_stuff.setText(stuff['stuffid'] + stuff['stuffname'])
        self.label_spec.setText(stuff['spec'])
        self.label_package.setText(stuff['package'])
        self.label_unit.setText(stuff['spunit'])
        self.dateEdit_makedate.setDate(user.now_date)
        self.dateEdit_invaliddate.setDate(user.now_date + datetime.timedelta(
            days=stuff['expireddays']))

        self.new_detail['stuffid'] = stuff['stuffid']
        self.new_detail['stuffname'] = stuff['stuffname']
        self.new_detail['spec'] = stuff['spec']
        self.new_detail['package'] = stuff['package']
        self.new_detail['unit'] = stuff['spunit']
        self.new_detail['stufftype'] = stuff['stufftype']

        self.lineEdit_batchno.setFocus()
        self.get_producer_list(p_int)

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        text = ''
        if self.lineEdit_stuff.text() == '':
            text = "物料不能为空!\n"
        if self.lineEdit_amount.text() in ('', '0'):
            text += "到货数量不能为空!\n"
        if self.lineEdit_batchno.text() == '':
            text += "进厂批号不能为空!\n"
        if len(text) > 0:
            message = MessageBox(self, text="以下信息填写错误", informative=text)
            message.show()
            return
        if len(self.new_detail):
            if self.spid:
                key_dict_supplyer = {'autoid': self.spid}
                supplyer_list = self.SC.get_supply(False,
                                                   *VALUES_TUPLE_SUPPLYER,
                                                   **key_dict_supplyer)
                if len(supplyer_list):
                    supplyer = supplyer_list[0]
                    self.new_detail['supid'] = supplyer['supid']
                    self.new_detail['supname'] = supplyer['supname']
                self.new_detail['paperno'] = self.paperno
                self.new_detail['papertype'] = self.papertype
                self.new_detail['checkindate'] = user.now_date
            res = self.WC.update_stuffcheckinlist(self.autoid,
                                                  **self.new_detail)

            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
class PurchaseRegistrationModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(PurchaseRegistrationModule, self).__init__(parent)
        self.setupUi(self)
        if '28' not in user.powers:
            self.close()
        if user.powers['28'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['28'])

        self.WC = WarehouseController()
        self.LC = LabrecordsController()
        self.SC = SupplyerController()
        self.SFC = StuffController()
        self.CI = CheckItem()
        self.groupBox.setVisible(False)
        self.spid = 0
        self.paperno = ''
        self.supid = ''
        self.supname = ''

        self.get_order_list()

    def get_order_list(self):
        self.treeWidget_orderlist.clear()
        self.treeWidget_orderlist.hideColumn(0)
        index = self.tabWidget.currentIndex()
        key_dict = {'status': index, 'papertype': 0}
        order_list = self.WC.get_stuffcheckin(False, *VALUES_TUPLE_ORDER,
                                              **key_dict)
        if not len(order_list):
            return
        for item in order_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_orderlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['paperno'])
            qtreeitem.setText(2, item['supid'] + ' ' + item['supname'])
            qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname'])
            qtreeitem.setText(4, str(item['buydate']))
            qtreeitem.setText(5, item['buyerid'] + ' ' + item['buyername'])
            qtreeitem.setText(6, item['pppaperno'])
            qtreeitem.setText(7, item['remark'])
        for i in range(1, 8):
            self.treeWidget_orderlist.resizeColumnToContents(i)

    def get_stuff_list(self):

        self.treeWidget_stufflist.clear()
        self.treeWidget_stufflist.hideColumn(0)
        index = self.tabWidget.currentIndex()
        key_dict = {'paperno': self.paperno, 'papertype': 0}
        stuff_list = self.WC.get_stuffcheckinlist(False, *VALUES_TUPLE_STUFF,
                                                  **key_dict)
        if not len(stuff_list):
            return
        for item in stuff_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STATUS[item['status']])
            qtreeitem.setText(2, item['stuffid'] + ' ' + item['stuffname'])
            qtreeitem.setText(3, item['batchno'])
            qtreeitem.setText(4, item['mbatchno'])
            qtreeitem.setText(5, STUFF_KIND[item['stufftype']])
            qtreeitem.setText(6, item['spec'])
            qtreeitem.setText(7, item['package'])
            qtreeitem.setText(8, item['position'])
            qtreeitem.setText(9, str(item['amount']))
            qtreeitem.setText(10, str(item['piamount']))
            qtreeitem.setText(11, item['unit'])
            qtreeitem.setText(12, item['producer'])
        for i in range(1, 13):
            self.treeWidget_stufflist.resizeColumnToContents(i)

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        tab = getattr(self, 'tab_' + str(p_int))
        tab.setLayout(self.gridLayout_2)
        self.groupBox.setVisible(False)
        self.get_order_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_orderlist_itemClicked(self, qtreeitem, p_int):
        self.groupBox.setVisible(True)

        self.paperno = qtreeitem.text(1)
        self.supid = qtreeitem.text(2).split(' ')[0]
        self.supname = qtreeitem.text(2).split(' ')[1]
        key_dict = {'supid': self.supid, 'supname': self.supname}
        res = self.SC.get_supply(True, *VALUES_TUPLE_SUPPLYER, **key_dict)
        if len(res):
            self.spid = res[0]
        self.get_stuff_list()

    @pyqtSlot(QPoint)
    def on_treeWidget_orderlist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        id = 0
        index = self.tabWidget.currentIndex()
        if index != 0:
            return
            # 返回调用者的对象
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        if current_item is not None:
            id = int(current_item.text(0))

        menu = QMenu()
        button1 = menu.addAction("新增登记单")
        button2 = menu.addAction("设置为完成状态")
        button3 = menu.addAction("设置为其他状态")

        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)

        if action == button1:
            detail = NewPurchRegModule(self)
            detail.accepted.connect(self.get_order_list)
            detail.show()

        elif action == button2:
            if id is None:
                return
            key_dict = {'status': 1}
            self.WC.update_stuffcheckin(id, **key_dict)
            self.get_order_list()
        elif action == button3:
            if id is None:
                return
            key_dict = {'status': 2}
            self.WC.update_stuffcheckin(id, **key_dict)
            self.get_order_list()

    @pyqtSlot(QPoint)
    def on_treeWidget_stufflist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        id = 0
        index = self.tabWidget.currentIndex()
        if index != 0:
            return
            # 返回调用者的对象
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        if current_item is not None:
            id = int(current_item.text(0))

        menu = QMenu()
        button1 = menu.addAction("增加")
        button2 = menu.addAction("修改")
        button3 = menu.addAction("删除")
        button4 = menu.addAction("请验单")
        button5 = menu.addAction("不合格品处理申请")
        button6 = menu.addAction("不合格品处理意见")

        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)

        if action == button1:
            detail = EditRegStuffModule(spid=self.spid,
                                        paperno=self.paperno,
                                        parent=self)
            detail.accepted.connect(self.get_stuff_list)
            detail.show()

        elif action == button2:
            if not id:
                return
            detail = EditRegStuffModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_stuff_list)
            detail.show()
        elif action == button3:
            if not id:
                return
            if current_item.text(1) not in ("登记", "请验中"):
                return
            key_dict_lab = {'autoid': id}
            lab_list = self.WC.get_stuffcheckinlist(True, *VALUES_TUPLE_LAB,
                                                    **key_dict_lab)
            self.LC.delete_labrecord(list(lab_list))
            self.LC.delete_labitem(list(lab_list))
            self.WC.delete_stuffcheckinlist(id)
            self.get_stuff_list()
        elif action == button4:
            if not id:
                return
            status = current_item.text(1)
            if status not in ("登记", "请验中"):
                return
            stuffid = current_item.text(2).split(' ')[0]
            stuffname = current_item.text(2).split(' ')[1]
            key_dict = {'stuffid': stuffid, 'stuffname': stuffname}
            checkunit = ''
            res = self.SFC.get_stuffdict(True, *VALUES_TUPLE_SD, **key_dict)
            if len(res):
                checkunit = res[0]
            key_dict_lab = {'ciid': id, 'labtype': 0}
            labrecord_list = self.LC.get_labrecord(False, **key_dict_lab)
            if not len(labrecord_list):
                kwargs = {
                    'labtype': 0,
                    'chkid': stuffid,
                    'chkname': stuffname,
                    'batchno': current_item.text(3),
                    'mbatchno': current_item.text(4),
                    'spec': current_item.text(6),
                    'package': current_item.text(7),
                    'producer': current_item.text(12),
                    'supplyer': self.supname,
                    'ciid': int(current_item.text(0)),
                    'createdate': user.now_date,
                    'checkamount': decimal.Decimal(current_item.text(9)),
                    'caunit': current_item.text(11),
                    'sampleunit': checkunit,
                    'samplesource': self.supname
                }
                labrecord = self.LC.update_labrecord(**kwargs)
                key_dict_checkitem = {'stuffid': stuffid, 'itemtype': 0}
                checkitems = self.CI.get_checkitems(False,
                                                    *VALUES_TUPLE_CHECKITEM,
                                                    **key_dict_checkitem)
                for item in checkitems:
                    kwargs_checkitem = {
                        'lrid': labrecord.autoid,
                        'seqid': item['seqid'],
                        'itemname': item['itemname'],
                        'kind': item['kind'],
                        'referencevalue': item['referencevalue'],
                        'labvalue': item['referencevalue'],
                        'putintype': item['putintype'],
                        'startdate': user.now_date,
                        'enddate': user.now_date,
                        'checked': 2
                    }
                    self.LC.update_labitem(**kwargs_checkitem)
            else:
                labrecord = labrecord_list[0]
            self.WC.update_stuffcheckinlist(id, lrid=labrecord.autoid)
            detail = ApplycheckModule(autoid=labrecord.autoid, parent=self)
            detail.applyed.connect(self.get_stuff_list)
            detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_stufflist_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        status = qtreeitem.text(1)
        if status != "登记":
            return
        id = int(qtreeitem.text(0))
        detail = EditRegStuffModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_stuff_list)
        detail.show()
class EditpurchasingplanModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditpurchasingplanModule, self).__init__(parent)
        self.setupUi(self)

        if '6' not in user.powers:
            self.close()
        if user.powers['6'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['6'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)

        self.ori_detail = dict()
        self.new_detail = dict()
        self.SC = SupplyerController()
        row = ('autoid', 'supid', 'supname')
        key = ('supid', 'supname', 'inputcode')
        row_name = ("id", "供应商编号", "供应商名称")
        self.lineEdit_supplyer.setup('Supplyer', row, key, row_name, None, 539,
                                     240)

        self.autoid = autoid

        self.get_detail()

    def get_detail(self):
        if not self.autoid:
            self.pushButton_creator.setSign(
                True, user.user_id + ' ' + user.user_name)
            self.dateEdit_createdate.setDate(user.now_date)
            self.dateEdit_invaliddate.setDate(user.now_date +
                                              datetime.timedelta(weeks=4))
            self.lineEdit_paperno.setText(self.get_max_paperno())
            return
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_purchasingplan(False, *VALUES_TUPLE, **key_dict)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.lineEdit_paperno.setText(self.ori_detail['paperno'])
        self.lineEdit_supplyer.setText(self.ori_detail['supid'] + ' ' +
                                       self.ori_detail['supname'])
        self.pushButton_creator.setSign(
            True, self.ori_detail['creatorid'] + ' ' +
            self.ori_detail['creatorname'])
        self.dateEdit_createdate.setDate(self.ori_detail['createdate'])
        self.dateEdit_invaliddate.setDate(self.ori_detail['invaliddate'])
        self.lineEdit_remark.setText(self.ori_detail['remark'])
        self.pushButton_warrantor.setSign(
            True, self.ori_detail['warrantorid'] + ' ' +
            self.ori_detail['warrantorname'])

    def get_max_paperno(self):
        res = self.SC.get_purchasingplan(True, *VALUES_TUPLE_PAPERNO)
        if not len(res):
            return ''
        max_paperno = res.order_by('-paperno')[0]
        num = re.findall('\d+', max_paperno)[-1]
        new_num = str(int(num) + 1)
        i = len(new_num)
        while i < len(num):
            new_num = '0' + new_num
            i += 1

        return max_paperno.replace(num, new_num)

    @pyqtSlot(str)
    def on_lineEdit_paperno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['paperno']:
                self.new_detail['paperno'] = p_str
            else:
                try:
                    del self.new_detail['paperno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['paperno'] = p_str

    @pyqtSlot(object)
    def on_lineEdit_supplyer_getItem(self, p_obj):
        id = p_obj.text(1)
        name = p_obj.text(2)
        spid = 0
        if id not in ('', ' '):
            key_dict = {'supid': id, 'supname': name}
            res = self.SC.get_supply(True, *VALUES_TUPLE_SUPPLYER, **key_dict)
            if len(res):
                spid = res[0]
        try:
            if id != self.ori_detail['supid'] or name != self.ori_detail[
                    'supname']:
                self.new_detail['supid'] = id
                self.new_detail['supname'] = name
                self.new_detail['spid'] = spid
            else:
                try:
                    del self.new_detail['supid']
                    del self.new_detail['supname']
                    del self.new_detail['spid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['supid'] = id
            self.new_detail['supname'] = name
            self.new_detail['spid'] = spid

    @pyqtSlot(bool, str)
    def on_pushButton_creator_signChanged(self, p_bool, p_str):
        id, name = p_str.split(' ') if p_bool else ('', '')
        try:
            if id != self.ori_detail['creatorid'] or name != self.ori_detail[
                    'creatorname']:
                self.new_detail['creatorid'] = id
                self.new_detail['creatorname'] = name
            else:
                try:
                    del self.new_detail['creatorid']
                    del self.new_detail['creatorname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['creatorid'] = id
            self.new_detail['creatorname'] = name

    @pyqtSlot(QDate)
    def on_dateEdit_createdate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['createdate']) is str:
                self.new_detail['createdate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['createdate']):
                self.new_detail['createdate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['createdate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['createdate'] = q_date.toPyDate()

    @pyqtSlot(QDate)
    def on_dateEdit_invaliddate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['invaliddate']) is str:
                self.new_detail['invaliddate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['invaliddate']):
                self.new_detail['invaliddate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['invaliddate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['invaliddate'] = q_date.toPyDate()

    @pyqtSlot(str)
    def on_lineEdit_remark_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['remark']:
                self.new_detail['remark'] = p_str
            else:
                try:
                    del self.new_detail['remark']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['remark'] = p_str

    @pyqtSlot(bool, str)
    def on_pushButton_warrantor_signChanged(self, p_bool, p_str):
        id, name = p_str.split(' ') if p_bool else ('', '')
        try:
            if id != self.ori_detail['warrantorid'] or name != self.ori_detail[
                    'warrantorname']:
                self.new_detail['warrantorid'] = id
                self.new_detail['warrantorname'] = name
            else:
                try:
                    del self.new_detail['warrantorid']
                    del self.new_detail['warrantorname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['warrantorid'] = id
            self.new_detail['warrantorname'] = name

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if 'paperno' in self.new_detail:
            key_dict = {'paperno': self.new_detail['paperno']}
            res = self.SC.get_purchasingplan(True, *VALUES_TUPLE_PAPERNO,
                                             **key_dict)
            if len(res) > 0:
                message = MessageBox(self,
                                     text="单号重复,请修改后重新提交",
                                     informative="已经存在单号为" +
                                     self.new_detail['paperno'] + "的记录了!")
                message.show()
                self.lineEdit_paperno.setFocus()
                return
        if len(self.new_detail):
            res = self.SC.update_purchasingplan(self.autoid, **self.new_detail)
            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()