예제 #1
0
    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()
예제 #2
0
 def __init__(self):
     self.SC = StuffController()
     self.SLC = SaleController()
     self.SP = SupplyerController()
     self.WM = WarehouseModel()
     self.WC = WorkshopController()
     self.PC = ProductController()
    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()
예제 #4
0
    def __init__(self, spid, parent=None):
        super(SelectstuffModule, self).__init__(parent)
        self.setupUi(self)
        self.spid = spid
        self.SC = SupplyerController()
        self.SFC = StuffController()

        self.get_stufflist()
예제 #5
0
    def __init__(self, parent=None):
        super(NewPurchRegModule, self).__init__(parent)
        self.order_list = []
        self.detail = dict()
        self.paperno = ''
        self.setupUi(self)
        self.WC = WarehouseController()
        self.SC = SupplyerController()

        self.get_orderlist()
예제 #6
0
 def __init__(self, parent=None):
     super(SupplyerListModule, self).__init__(parent)
     self.setupUi(self)
     if '3' not in user.powers:
         self.close()
     if user.powers['3'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['3'])
     self.SC = SupplyerController()
     self.IC = ImageController()
     self.kind_list = []
     self.curremt_kind = 0
     self.treeWidget_kind.hideColumn(1)
     self.treeWidget_detail.hideColumn(0)
     self.get_kind_list()
     self.get_supplyer_list()
예제 #7
0
    def __init__(self, parent=None):
        super(PurchasingplanModule, 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'])

        self.SC = SupplyerController()
        self.ppid = None
        self.ori_detail = dict()
        self.new_detail = dict()
        self.groupBox.setVisible(False)
        # 获取当前状态的采购记录
        self.get_orderdetail()
예제 #8
0
    def __init__(self, spid, ppid=None, autoid=None, parent=None):
        super(EditpurstuffModule, self).__init__(parent)
        self.ori_detail = dict()
        self.new_detail = dict()
        self.SC = SupplyerController()
        self.SFC = StuffController()
        self.setupUi(self)
        # row = ('autoid', 'stuffid', 'stuffname', 'spec', 'package')
        # key = ('stuffid', 'stuffname', 'stuffkind', 'inputcode')
        # row_name = ('id', '物料编号', '物料名称', '含量规格', '包装规格')
        # self.lineEdit_supplyer.setup('Supplyer', row, key, row_name, 539, 240)

        self.autoid = autoid
        self.spid = spid
        self.ppid = ppid

        self.get_detail()
        self.set_amount_validator()
    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()
예제 #10
0
 def __init__(self, autoid=None, sdid=None, parent=None):
     super(StuffSupplyerModule, self).__init__(parent)
     self.setupUi(self)
     # 修改前数据,若为新建则为空
     self.ori_detail = object
     # 修改后的数据,自动把修改过的数据添加到字典中,
     # 若恢复原来的数据或者删除,则字典中也删除
     self.new_detail = {}
     # 物料字典中的autoid,由生成界面时传入
     self.sdid = sdid
     # 物料供应商的autoid,仅修改记录时才有值传入
     self.autoid = autoid
     # 数据库操作类
     self.SC = SupplyerController()
     return_row = ('autoid', 'supid', 'supname')
     condition_key = ('supid', 'supname', 'inputcode')
     treeheader_name = ["id", "编号", "名称"]
     self.lineEdit_supplyer.setup(
         'Supplyer', return_row, condition_key, treeheader_name, None,
         500, 180
     )
     self.get_detail()
예제 #11
0
 def __init__(self, autoid=None, parent=None):
     super(EditSupplyerDetailModule, self).__init__(parent)
     self.setupUi(self)
     if '3' not in user.powers:
         self.close()
     if user.powers['3'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['3'])
     if self.power[1] == '0':
         self.pushButton_accept.setVisible(False)
         self.pushButton_cancel.setVisible(False)
     self.autoid = autoid
     self.docid = 0
     self.current_content = QWidget()
     self.ori_detail = dict()
     self.new_detail = dict()
     self.current_img = object
     self.current_page = object
     self.SC = SupplyerController()
     self.SDC = SelfdefinedformatController()
     self.IC = ImageController()
     self.treeWidget_stuff.hideColumn(0)
     self.treeWidget_revalution.hideColumn(0)
     self.treeWidget_imagenamelist.hideColumn(0)
     self.treeWidget_imagenamelist.hideColumn(1)
     # 自动缩放
     self.label_image.setScaledContents(True)
     return_row = ('parentid', 'autoid', 'kindname')
     condition_key = {'autoid', 'kindname', 'inputcode'}
     treeheader_name = ['parentid', '编号', '名称']
     condition = {'kind': 0}
     self.lineEdit_kind.setup('Treestructure',
                              return_row,
                              condition_key,
                              treeheader_name,
                              condition,
                              treewidth=300)
     self.get_detail()
예제 #12
0
class SelectstuffModule(QDialog, Ui_Dialog):
    selected = pyqtSignal(int)

    def __init__(self, spid, parent=None):
        super(SelectstuffModule, self).__init__(parent)
        self.setupUi(self)
        self.spid = spid
        self.SC = SupplyerController()
        self.SFC = StuffController()

        self.get_stufflist()

    def get_stufflist(self):
        self.treeWidget_stufflist.clear()
        self.treeWidget_stufflist.hideColumn(0)
        key_dict = {'spid': self.spid}
        id_list = self.SC.get_stuffsupplyer(True, *VALUES_TUPLES_SD,
                                            **key_dict)
        if not len(id_list):
            return
        key_dict_stuff = {'autoid__in': id_list}
        res = self.SFC.get_stuffdict(False, *VALUES_TUPLES_STUFF,
                                     **key_dict_stuff)

        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['stuffid'])
            qtreeitem.setText(2, item['stuffname'])
            qtreeitem.setText(3, item['spec'])
            qtreeitem.setText(4, item['package'])

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

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_stufflist_itemDoubleClicked(self, qtreeitem, p_int):
        self.selected.emit(int(qtreeitem.text(0)))
        self.accept()

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        current_item = self.treeWidget_stufflist.currentItem()
        if current_item is not None:
            self.selected.emit(int(current_item.text(0)))
            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
예제 #13
0
    def __init__(self, autoid=None, parent=None):
        super(EditStuffDetailModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid = autoid

        self.SC = StuffController()
        self.LC = LabrecordsController()
        self.PC = ProductController()
        self.SPC = SupplyerController()
        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        if len(self.ori_detail):
            stufftype = self.ori_detail['stufftype']
            if stufftype == 1:
                self.tab.removeTab(4)
                self.tab.removeTab(1)
            else:
                self.tab.removeTab(3)
                self.tab.removeTab(2)
        self.get_formula()
        self.get_checkitem(0, self.treeWidget_checkitem)
        self.get_checkitem(2, self.treeWidget_precheckitem)
        self.get_stuffsupplyer()
예제 #14
0
    def __init__(self, parent=None):
        super(PurStuffCheckInModule, self).__init__(parent)
        self.setupUi(self)
        if '29' not in user.powers:
            self.close()
        if user.powers['29'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['29'])

        self.WC = WarehouseController()
        self.LC = LabrecordsController()
        self.SC = SupplyerController()
        self.SFC = StuffController()

        self.get_stuff_list()
예제 #15
0
class EditSupplyerDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditSupplyerDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '3' not in user.powers:
            self.close()
        if user.powers['3'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['3'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.docid = 0
        self.current_content = QWidget()
        self.ori_detail = dict()
        self.new_detail = dict()
        self.current_img = object
        self.current_page = object
        self.SC = SupplyerController()
        self.SDC = SelfdefinedformatController()
        self.IC = ImageController()
        self.treeWidget_stuff.hideColumn(0)
        self.treeWidget_revalution.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)
        # 自动缩放
        self.label_image.setScaledContents(True)
        return_row = ('parentid', 'autoid', 'kindname')
        condition_key = {'autoid', 'kindname', 'inputcode'}
        treeheader_name = ['parentid', '编号', '名称']
        condition = {'kind': 0}
        self.lineEdit_kind.setup('Treestructure',
                                 return_row,
                                 condition_key,
                                 treeheader_name,
                                 condition,
                                 treewidth=300)
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            self.dateEdit_validdate.setDate(user.now_date)
            return
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_data(0, False, *VALUE_TUPLE_SUP, **key_dict)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.lineEdit_supid.setText(self.ori_detail['supid'])
        self.lineEdit_supname.setText(self.ori_detail['supname'])
        self.lineEdit_inputcode.setText(self.ori_detail['inputcode'])
        self.lineEdit_kind.setText(
            str(self.ori_detail['tstkind']) + ' ' + self.ori_detail['tstname'])
        self.lineEdit_address.setText(self.ori_detail['address'])
        self.lineEdit_postzip.setText(self.ori_detail['postzip'])
        self.lineEdit_charger.setText(self.ori_detail['charger'])
        self.lineEdit_telno.setText(self.ori_detail['telno'])
        self.lineEdit_chargertitle.setText(self.ori_detail['chargertitle'])
        self.lineEdit_email.setText(self.ori_detail['email'])
        self.lineEdit_bankname.setText(self.ori_detail['bankname'])
        self.lineEdit_bankaccount.setText(self.ori_detail['bankaccount'])
        self.lineEdit_taxno.setText(self.ori_detail['taxno'])
        self.dateEdit_validdate.setDate(self.ori_detail['validdate'])
        self.plainTextEdit_remark.setPlainText(self.ori_detail['remark'])

    def get_image(self):
        self.treeWidget_imagenamelist.clear()
        if self.autoid is None:
            return
        key_dict = {'scid': self.autoid, 'kind': 0}
        res = self.IC.get_data(0, False, *VALUE_TUPLE_IMRELA, **key_dict)
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['imageid']))
            qtreeitem.setText(2, item['title'])
            qtreeitem.setText(3, item['creatorid'] + item['creatorname'])
            qtreeitem.setText(4, str(item['createdate']))

    def get_format(self):
        if self.autoid is None:
            return
        self.treeWidget_revalution.clear()
        key_dict = {'spid': self.autoid}
        res = self.SC.get_data(4, False, *VALUE_TUPLE_SR, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_revalution)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['title'])
            qtreeitem.setText(2, str(item['createdate']))
            qtreeitem.setText(3, item['creatorid'] + ' ' + item['creatorname'])
        for i in range(1, 4):
            self.treeWidget_revalution.resizeColumnToContents(i)

    def get_stuff(self):
        if self.autoid is None:
            return
        self.treeWidget_stuff.clear()
        key_dict = {'spid': self.autoid}
        res = self.SC.get_data(1, False, **key_dict).extra(
            select={
                'autoid': 'stuffdictionary.autoid',
                'stuffid': 'stuffdictionary.stuffid',
                'stuffname': 'stuffdictionary.stuffname',
                'stufftype': 'stuffdictionary.stufftype',
                'spec': 'stuffdictionary.spec',
                'package': 'stuffdictionary.package'
            },
            tables=['stuffdictionary'],
            where=['stuffdictionary.autoid=stuffsupplyers.sdid'
                   ]).values(*VALUE_TUPLE_STUFF)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_stuff)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STUFFTYPE[item['stufftype']])
            qtreeitem.setText(2, item['stuffid'])
            qtreeitem.setText(3, item['stuffname'])
            qtreeitem.setText(4, item['spec'])
            qtreeitem.setText(5, item['package'])
        for i in range(1, 6):
            self.treeWidget_stuff.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):

        img_id = int(qtreeitem.text(1))
        key_dict = {'autoid': img_id}
        res = self.IC.get_data(1, False, *VALUE_TUPLE_IM, **key_dict)
        if not len(res):
            return
        ext = res[0]['ext']
        image = res[0]['img']

        if ext.lower() == 'pdf':
            self.comboBox_jumpto.setVisible(True)
            self.pushButton_prepage.setVisible(True)
            self.pushButton_nextpage.setVisible(True)
            self.current_img = fitz.Document(stream=image, filetype='pdf')
            page_count = self.current_img.pageCount
            page_list = []
            self.comboBox_jumpto.clear()
            for i in range(1, page_count + 1):
                page_list.append('第' + str(i) + '页')
            self.comboBox_jumpto.addItems(page_list)
            self.current_page = self.current_img.loadPage(0)

        else:
            self.comboBox_jumpto.setVisible(False)
            self.pushButton_prepage.setVisible(False)
            self.pushButton_nextpage.setVisible(False)
            img = QImage.fromData(image)
            self.current_img = QPixmap.fromImage(img)
            self.label_image.setPixmap(self.current_img)

        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except (ValueError, AttributeError):
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot(QPoint)
    def on_treeWidget_imagenamelist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        # 返回调用者的对象
        sender_widget = self.sender()
        menu = QMenu()
        button1 = menu.addAction("新增图片")
        button2 = menu.addAction("修改图片")
        button3 = menu.addAction("删除图片")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        res = "rollback"
        # 增加
        if action == button1:
            img_names, img_type = QFileDialog.getOpenFileNames(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            for item in img_names:
                imagename_no_ext = item.split("/")[-1]
                image_ext = item.split(".")[1]
                if image_ext.lower() not in ("jpg", "png", "bmp", "gif",
                                             "pdf"):
                    continue
                fp = open(item, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'kind': 0,
                    'scid': self.autoid,
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail)

        # 修改
        elif action == button2:
            rela_id = self.treeWidget_imagenamelist.currentItem().text(0)
            img_id = self.treeWidget_imagenamelist.currentItem().text(1)
            img_name, img_type = QFileDialog.getOpenFileName(
                self, "打开图片",
                os.path.expanduser("~") + "\Desktop",
                "*.jpg;;*.png;;*.bmp;;*.gif;;*.pdf;;All Files(*)")
            imagename_no_ext = img_name.split("/")[-1]
            image_ext = img_name.split(".")[1]
            if image_ext.lower() in ("jpg", "png", "bmp", "gif", "pdf"):
                fp = open(img_name, 'rb')
                with fp:
                    image_byte = fp.read()
                    fp.close()
                imagedetail = {'img': image_byte, 'ext': image_ext}
                reladetail = {
                    'title': imagename_no_ext,
                    'creatorid': user.user_id,
                    'creatorname': user.user_name,
                    'createdate': user.now_date
                }

                res = self.IC.update_images(reladetail, imagedetail, rela_id,
                                            img_id)

        # 删除
        elif action == button3:
            select_item = sender_widget.selectedItems()
            rela_id = []
            img_id = []
            for item in select_item:
                rela_id.append(item.text(0))
                img_id.append(item.text(1))
            res = self.IC.delete_images(rela_id, img_id)

        if res == "accept":
            self.get_image()

    @pyqtSlot(str)
    def on_lineEdit_supid_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['supid']:
                self.new_detail['supid'] = p_str
            else:
                try:
                    del self.new_detail['supid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['supid'] = 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(str)
    def on_lineEdit_supname_textChanged(self, p_str):
        self.lineEdit_inputcode.setText(Inputcode.make_inputcode(p_str))
        try:
            if p_str != self.ori_detail['supname']:
                self.new_detail['supname'] = p_str
            else:
                try:
                    del self.new_detail['supname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['supname'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_kind_textChanged(self, p_str):
        if len(p_str.split(' ')) != 2 and p_str != '':
            return
        id, name = p_str.split(' ') if p_str != '' else ('', '')
        try:
            if id != self.ori_detail['tstkind'] or name != \
                    self.ori_detail['tstname']:
                self.new_detail['tstkind'] = id
                self.new_detail['tstname'] = name
            else:
                try:
                    del self.new_detail['tstkind']
                    del self.new_detail['tstname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['tstkind'] = id
            self.new_detail['tstname'] = name

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

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

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

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

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

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

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

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

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

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

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

    @pyqtSlot()
    def on_plainTextEdit_remark_textChanged(self):
        p_str = self.plainTextEdit_remark.toPlainText()
        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()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        condition = dict()
        if self.autoid is not None:
            condition['autoid'] = self.autoid
        self.SC.update_data(0, condition, **self.new_detail)
        self.accept()

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

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_revalution_itemDoubleClicked(self, qtreeitem, p_int):
        if hasattr(self.current_content, 'flat'):
            if self.current_content.flat:
                dialog = MessageBox(self,
                                    title="提醒",
                                    text="文档尚未保存",
                                    informative="是否要保存文档",
                                    yes_text="保存",
                                    no_text="放弃保存")
                result = dialog.exec()
                if result == QMessageBox.Yes:
                    # 调用保存的槽函数
                    self.on_pushButton_save_clicked()
        self.docid = int(qtreeitem.text(0))
        key_dict = {'autoid': self.docid}
        res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict)
        if not len(res):
            return
        content = str(res[0])
        if not self.gridLayout_7.isEmpty():
            self.gridLayout_7.removeWidget(self.current_content)
            self.current_content.close()
        self.current_content = XMLReadWrite(self)
        self.current_content.openxml(content)
        self.gridLayout_7.addWidget(self.current_content)
        self.current_content.__setattr__('autoid', self.docid)

    @pyqtSlot()
    def on_pushButton_save_clicked(self):
        if self.docid == 0:
            return
        if not hasattr(self.current_content, 'flat'):
            return
        newcontent = self.current_content.get_content()
        condition = {'autoid': self.docid}
        kwargs = {'conclusion': newcontent}
        self.SC.update_data(4, condition, **kwargs)
        self.current_content.flat = 0

    @pyqtSlot()
    def on_pushButton_undo_clicked(self):
        if hasattr(self.current_content, 'flat'):
            self.current_content.flat = 0

    @pyqtSlot(QPoint)
    def on_treeWidget_revalution_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        if self.autoid is None:
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        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 = SelectSelfDefineFormatModule('4', self)
            detail.selected.connect(self.new_records)
            detail.accepted.connect(self.get_format)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            if hasattr(self.current_content, 'flat'):
                if self.current_content.flat:
                    dialog = MessageBox(self,
                                        title="提醒",
                                        text="文档尚未保存",
                                        informative="是否要保存文档",
                                        yes_text="保存",
                                        no_text="放弃保存")
                    result = dialog.exec()
                    if result == QMessageBox.Yes:
                        # 调用保存的槽函数
                        self.on_pushButton_accept_clicked()
            self.docid = int(current_item.text(0))
            key_dict = {'autoid': self.docid}
            res = self.SC.get_data(4, True, *VALUE_TUPLE_SD, **key_dict)
            if not len(res):
                return
            content = str(res[0])
            if not self.gridLayout_7.isEmpty():
                self.gridLayout_7.removeWidget(self.current_content)
                self.current_content.close()
            self.current_content = XMLReadWrite(self)
            self.current_content.openxml(content)
            self.gridLayout_7.addWidget(self.current_content)
            self.current_content.__setattr__('autoid', self.docid)
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.SC.delete_data(4, condition)
            self.get_format()

    def new_records(self, q_list):
        detail = {
            'creatorid': user.user_id,
            'creatorname': user.user_name,
            'createdate': user.now_date,
            'spid': self.autoid
        }
        key_dict = {'autoid__in': q_list}
        sd_list = self.SDC.get_data(0, **key_dict)
        for item in q_list:
            for sd in sd_list:
                if item == sd.autoid:
                    detail['title'] = sd.formatname
                    detail['conclusion'] = sd.format
                    self.SC.update_data(4, **detail)
                    break

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        if p_int == 0:
            self.get_detail()
        elif p_int == 1:
            self.get_image()
        elif p_int == 2:
            self.get_format()
        elif p_int == 3:
            self.get_stuff()
        else:
            pass
예제 #16
0
class NewPurchRegModule(QDialog, Ui_Dialog):
    def __init__(self, parent=None):
        super(NewPurchRegModule, self).__init__(parent)
        self.order_list = []
        self.detail = dict()
        self.paperno = ''
        self.setupUi(self)
        self.WC = WarehouseController()
        self.SC = SupplyerController()

        self.get_orderlist()

    def get_orderlist(self):
        self.treeWidget_orderlist.clear()
        # self.treeWidget_orderlist.hideColumn(0)
        key_dict = {'status': 1}
        self.order_list = self.SC.get_purchasingplan(False,
                                                     *VALUES_TUPLE_ORDER,
                                                     **key_dict)
        if not len(self.order_list):
            return
        for item in self.order_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_orderlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['paperno'])
            qtreeitem.setText(2, str(item['createdate']))
            qtreeitem.setText(3, item['supid'] + ' ' + item['supname'])
            qtreeitem.setText(4, item['creatorid'] + ' ' + item['creatorname'])
        for i in range(2, 5):
            self.treeWidget_orderlist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_orderlist_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        for item in self.order_list:
            if id == item['autoid']:
                self.detail = item
                break
        if len(self.detail):
            self.paperno = self.set_regpaperno()
            self.lineEdit_regno.setText(self.paperno)
            self.lineEdit_purchdate.setText(str(self.detail['createdate']))
            self.lineEdit_buyer.setText(
                str(self.detail['creatorid']) + ' ' +
                self.detail['creatorname'])
            self.lineEdit_remark.setText(str(self.detail['remark']))
            self.lineEdit_supplyer.setText(
                str(self.detail['supid'] + ' ' + self.detail['supname']))
            self.lineEdit_purchno.setText(self.detail['paperno'])

    def set_regpaperno(self):
        key_dict = {'papertype': 0}
        res = self.WC.get_stuffcheckin(True, *VALUES_TUPLE_PAPERNO, **key_dict)
        if not len(res):
            return '0001'
        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()
    def on_pushButton_accept_clicked(self):
        if not self.detail:
            return
        kwargs = {
            'paperno': self.paperno,
            'pppaperno': self.detail['paperno'],
            'createdate': user.now_date,
            'creatorid': user.user_id,
            'creatorname': user.user_name,
            'supid': self.detail['supid'],
            'supname': self.detail['supname'],
            'remark': self.detail['remark'],
            'buyerid': self.detail['creatorid'],
            'buyername': self.detail['creatorname'],
            'buydate': self.detail['invaliddate'],
            'pikind': '采购',
            'papertype': 0,
            'status': 0
        }
        self.WC.new_stuffcheckin(self.detail['autoid'], **kwargs)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
예제 #17
0
class PurchasingplanModule(QWidget, Ui_Form):
    """ 采购计划表记录
    分3个标签,0:编辑状态;允许随意修改
            1:正在执行;只运行提交完成/退回编辑
            2:已完成;只能查看不能修改
    """

    def __init__(self, parent=None):
        super(PurchasingplanModule, 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'])

        self.SC = SupplyerController()
        self.ppid = None
        self.ori_detail = dict()
        self.new_detail = dict()
        self.groupBox.setVisible(False)
        # 获取当前状态的采购记录
        self.get_orderdetail()

    def get_orderdetail(self):
        self.treeWidget_orderlist.clear()
        self.treeWidget_orderlist.hideColumn(0)
        self.treeWidget_orderlist.hideColumn(1)

        index = self.tabWidget.currentIndex()
        key_dict_prod = {
                'status': index
            }

        res = self.SC.get_purchasingplan(
            False, *VALUES_TUPLE_ORDER, **key_dict_prod
        )
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_orderlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['spid']))
            qtreeitem.setText(2, item['paperno'])
            qtreeitem.setText(3, item['supid'] + ' ' + item['supname'])
            qtreeitem.setText(4, str(item['createdate']))
            qtreeitem.setText(5, item['creatorid'] + ' ' + item['creatorname'])
            qtreeitem.setText(
                6, item['warrantorid'] + ' ' + item['warrantorname']
            )
            qtreeitem.setText(7, str(item['invaliddate']))
            qtreeitem.setText(8, item['remark'])

        for i in range(2, 9):
            self.treeWidget_orderlist.resizeColumnToContents(i)

    # 获取物料信息
    def get_stuffdetail(self):
        self.treeWidget_stufflist.clear()
        self.treeWidget_stufflist.hideColumn(0)
        key_dict = {
            'ppid': self.ppid
        }
        res = self.SC.get_purchstuff(
            False, *VALUES_TUPLE_STUFF, **key_dict
        )
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
                qtreeitem.setText(0, str(item['autoid']))
                qtreeitem.setText(1, item['stuffid'] + ' ' + item['stuffname'])
                qtreeitem.setText(2, STUFF_TYPE[item['stufftype']])
                qtreeitem.setText(3, item['spec'])
                qtreeitem.setText(4, item['package'])
                qtreeitem.setText(5, str(item['amount']))
                qtreeitem.setText(6, str(item['arrivedamount']))
                qtreeitem.setText(7, item['unit'])
                qtreeitem.setText(8, item['producer'])

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

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

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_orderlist_itemClicked(self, qtreeitem, p_int):
        if not self.groupBox.isVisible():
            self.groupBox.setVisible(True)
        self.ppid = int(qtreeitem.text(0))
        self.get_stuffdetail()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_orderlist_itemDoubleClicked(self, qtreeitem, p_int):
        index = self.tabWidget.currentIndex()
        if index != 0:
            return
        id = int(qtreeitem.text(0))
        detail = EditpurchasingplanModule(id, self)
        detail.accepted.connect(self.get_orderdetail)
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_orderlist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        id = 0
        index = self.tabWidget.currentIndex()
        if index == 2:
            return
            # 返回调用者的对象
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        if current_item is not None:
            id = int(current_item.text(0))
        menu = QMenu()
        if index == 0:
            button1 = menu.addAction("新增计划单")
            button2 = menu.addAction("修改计划单")
            button3 = menu.addAction("删除计划单")
            button4 = menu.addAction("提交执行")
        elif index == 1:
            button5 = menu.addAction("完成计划单")
            button6 = menu.addAction("退回编辑")

        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if index == 0:
            if action == button1:
                detail = EditpurchasingplanModule(None, self)
                detail.accepted.connect(self.get_orderdetail)
                detail.show()
            elif action == button2:
                detail = EditpurchasingplanModule(id, self)
                detail.accepted.connect(self.get_orderdetail)
                detail.show()
            elif action == button3:
                if id is None:
                    return
                key_dict = {
                    'ppid': id
                }
                self.SC.delete_purchstuff(**key_dict)
                self.SC.delete_purchasingplan(id)
            elif action == button4:
                if id is None:
                    return
                warrantor = current_item.text(5)
                if warrantor in ('', ' '):
                    message = MessageBox(
                        self, text="无法提交执行", informative="批准人还没有签名"
                    )
                    message.show()
                    return
                key_dict = {
                    'status': 1
                }
                self.SC.update_purchasingplan(id, **key_dict)

        elif index == 1:
            if action == button5:
                if id is None:
                    return
                key_dict = {
                    'status': 2
                }
                self.SC.update_purchasingplan(id, **key_dict)
            elif action == button6:
                if id is None:
                    return
                key_dict = {
                    'status': 0
                }
                self.SC.update_purchasingplan(id, **key_dict)
        self.get_orderdetail()

    @pyqtSlot(QPoint)
    def on_treeWidget_stufflist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        id = []
        index = self.tabWidget.currentIndex()
        if index != 0:
            return
        order_item = self.treeWidget_orderlist.currentItem()
        if order_item is None:
            return
        ppid = order_item.text(0)
        spid = order_item.text(1)
        # 返回调用者的对象
        sender_widget = self.sender()
        select_items = sender_widget.selectedItems()
        if select_items is not None:
            for item in select_items:
                id.append(int(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 = EditpurstuffModule(spid, ppid, None, self)
            detail.accepted.connect(self.get_stuffdetail)
            detail.show()
        elif action == button2:
            current_item = sender_widget.currentItem()
            current_id = int(current_item.text(0))
            detail = EditpurchasingplanModule(spid, None, current_id, self)
            detail.accepted.connect(self.get_stuffdetail)
            detail.show()
        elif action == button3:
            if id is None:
                return
            key_dict = {
                'autoid__in': id
            }
            self.SC.delete_purchstuff(**key_dict)

        self.get_stuffdetail()
예제 #18
0
class EditStuffDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditStuffDetailModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid = autoid

        self.SC = StuffController()
        self.LC = LabrecordsController()
        self.PC = ProductController()
        self.SPC = SupplyerController()
        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        if len(self.ori_detail):
            stufftype = self.ori_detail['stufftype']
            if stufftype == 1:
                self.tab.removeTab(4)
                self.tab.removeTab(1)
            else:
                self.tab.removeTab(3)
                self.tab.removeTab(2)
        self.get_formula()
        self.get_checkitem(0, self.treeWidget_checkitem)
        self.get_checkitem(2, self.treeWidget_precheckitem)
        self.get_stuffsupplyer()

    def get_detail(self):
        if self.autoid is None:
            self.tab.setTabVisible(1, False)
            self.tab.setTabVisible(2, False)
            self.tab.setTabVisible(3, False)
            self.tab.setTabVisible(4, False)
            return
        condition = {'autoid': self.autoid}
        res = self.SC.get_data(0, False, *VALUES_TUPLE_SD, **condition)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.comboBox_stufftype.setCurrentIndex(self.ori_detail['stufftype'])
        self.lineEdit_stuffid.setText(self.ori_detail['stuffid'])
        self.lineEdit_stuffname.setText(self.ori_detail['stuffname'])
        self.lineEdit_kind.setText(self.ori_detail['kind'])
        self.lineEdit_allowno.setText(self.ori_detail['allowno'])
        self.lineEdit_inputcode.setText(self.ori_detail['inputcode'])
        self.lineEdit_spec.setText(self.ori_detail['spec'])
        self.comboBox_packageLv.setCurrentIndex(self.ori_detail['packagelv'])
        self.lineEdit_package.setText(self.ori_detail['package'])
        self.comboBox_midcheckunit.setCurrentText(
            self.ori_detail['midcheckunit'])
        self.comboBox_prodcheckunit.setCurrentText(
            self.ori_detail['prodcheckunit'])
        self.lineEdit_expired.setText(str(self.ori_detail['expireddays']))
        self.lineEdit_storage.setText(self.ori_detail['storage'])
        self.lineEdit_lowlimit.setText(str(self.ori_detail['lowlimit']))
        self.lineEdit_upperlimit.setText(str(self.ori_detail['upperlimit']))
        self.lineEdit_recheck.setText(str(self.ori_detail['countercheckdays']))
        self.lineEdit_cunit.setText(self.ori_detail['cunit'])

    def get_checkitem(self, itemtype, tree):
        tree.clear()
        condition = {'stuffid': self.autoid, 'itemtype': itemtype}
        res = self.LC.get_data(4, False, *VALUES_TUPLE_CI, **condition). \
            order_by('seqid')
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(tree)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['seqid']))
            qtreeitem.setText(2, item['kind'])
            qtreeitem.setText(3, item['itemname'])
            qtreeitem.setText(4, item['referencevalue'])
            qtreeitem.setText(5, RESTYPE[item['restype']])
            qtreeitem.setText(6, PUTINTYPE[item['putintype']])
        for i in range(1, 7):
            tree.resizeColumnToContents(i)

    def get_formula(self):
        if self.autoid is None:
            return
        self.treeWidget_formula.clear()
        condition = {'prodid': self.autoid, 'prodtype': 1}
        res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_formula)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, STUFFTYPE[item['stufftype']])
            qtreeitem.setText(2, item['stuffkind'])
            qtreeitem.setText(3, item['formula'])
            qtreeitem.setText(4, item['presexpression'])
            qtreeitem.setText(5, item['presunit'])
            qtreeitem.setText(6, item['pracexpression'])
            qtreeitem.setText(7, item['pracunit'])
            qtreeitem.setText(8, item['drawexpression'])
            qtreeitem.setText(9, item['drawunit'])
            qtreeitem.setText(10, str(item['precision']))
            qtreeitem.setText(11, str(item['loss']) + "%")
        for i in range(1, 12):
            self.treeWidget_formula.resizeColumnToContents(i)

    def get_stuffsupplyer(self):
        self.treeWidget_stuffsupplyer.clear()
        condition = {'sdid_id': self.autoid}
        res = self.SPC.get_data(1, **condition)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_stuffsupplyer)
            qtreeitem.setText(0, str(item.autoid))
            qtreeitem.setText(1, item.spid.supid)
            qtreeitem.setText(2, item.spid.supname)
            qtreeitem.setText(3, item.producer)
        for i in range(1, 4):
            self.treeWidget_stuffsupplyer.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_precheckitem_itemDoubleClicked(self, p_int):
        self.on_checkitem_itemDoubleClicked(self.treeWidget_precheckitem, 2)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_checkitem_itemDoubleClicked(self, p_int):
        self.on_checkitem_itemDoubleClicked(self.treeWidget_checkitem, 0)

    # 原料检验项目,双击打开详细信息
    def on_checkitem_itemDoubleClicked(self, tree, itemtype):
        # if self.power[1] == '0':
        #     return
        detail = SetCheckItem(self, tree.currentItem().text(0))
        detail.accepted.connect(lambda: self.get_checkitem(itemtype, tree))
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_precheckitem_customContextMenuRequested(self, pos):
        self.on_checkitem_customContextMenuRequested(
            self.treeWidget_precheckitem, 2, pos)

    @pyqtSlot(QPoint)
    def on_treeWidget_checkitem_customContextMenuRequested(self, pos):
        self.on_checkitem_customContextMenuRequested(self.treeWidget_checkitem,
                                                     0, pos)

    # 检验项目的右键菜单功能
    def on_checkitem_customContextMenuRequested(self, tree, itemtype, pos):
        # if self.power[1] == '0':
        #     return
        menu = QMenu()
        button1 = menu.addAction("增加")
        button2 = menu.addAction("修改")
        button3 = menu.addAction("删除")
        button4 = menu.addAction("复制")
        button5 = menu.addAction("黏贴")
        global_pos = tree.mapToGlobal(pos)
        action = menu.exec(global_pos)
        # 增加
        if action == button1:
            set_check_item = SetCheckItem(self,
                                          prodid=self.autoid,
                                          itemtype=itemtype)
            set_check_item.accepted.connect(
                lambda: self.get_checkitem(itemtype, tree))
            set_check_item.show()
        # 修改
        elif action == button2:
            current_item = tree.currentItem()
            if current_item is None:
                return
            id = int(current_item.text(0))
            set_check_item = SetCheckItem(self, autoid=id)
            set_check_item.accepted.connect(
                lambda: self.get_checkitem(itemtype, tree))
            set_check_item.show()
        # 删除
        elif action == button3:
            select_item = tree.selectedItems()
            checkitem_autoid = []
            for item in select_item:
                checkitem_autoid.append(item.text(0))
                condition = {'autoid__in': checkitem_autoid}
            self.LC.delete_data(4, condition)
            self.get_checkitem(itemtype, tree)
        # 复制
        elif action == button4:
            clipboard = QApplication.clipboard()
            items = tree.selectedItems()
            select_item = tree.mimeData(items)
            clipboard.setMimeData(select_item)
        # 黏贴
        elif action == button5:
            try:
                clipboard = QApplication.clipboard()
                data = clipboard.mimeData()
                # 获取当前行数,加1即为新的行号
                count = tree.topLevelItemCount()
                res = tree.dropMimeData(tree.invisibleRootItem(), count + 1,
                                        data, Qt.CopyAction)
                finnal_index = tree.topLevelItemCount()
                if res:
                    while count < finnal_index:
                        tree_item = tree.topLevelItem(count)
                        if tree_item is None:
                            raise AttributeError
                        detail = dict()
                        detail["seqid"] = tree_item.text(1)
                        detail["kind"] = tree_item.text(2)
                        detail["itemname"] = tree_item.text(3)
                        detail["referencevalue"] = tree_item.text(4)
                        detail["restype"] = RESTYPE.index(tree_item.text(5))
                        detail["putintype"] = PUTINTYPE.index(
                            tree_item.text(6))
                        detail["stuffid"] = self.autoid
                        detail["itemtype"] = itemtype
                        new_item = self.LC.update_data(4, **detail)
                        tree_item.setText(0, str(new_item.autoid))
                        count += 1
            except Exception as e:
                pass
        else:
            pass

    @pyqtSlot(QPoint)
    def on_treeWidget_formula_customContextMenuRequested(self, pos):
        # if self.power[1] == '0':
        #     return
        current_item = self.treeWidget_formula.currentItem()
        menu = QMenu()
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        global_pos = self.treeWidget_formula.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == action_1:
            detail = EditFormulaModule(prodid=self.autoid,
                                       prodtype=1,
                                       parent=self)
            detail.accepted.connect(self.get_formula)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = EditFormulaModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_formula)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            self.PC.delete_data(6, condition)
            self.get_formula()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_formula_itemDoubleClicked(self, qtreeitem, p_int):
        # if self.power[1] == '0':
        #     return
        id = int(qtreeitem.text(0))
        detail = EditFormulaModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_formula)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_stuffsupplyer_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = StuffSupplyerModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_stuffsupplyer)
        detail.show()

    # 物料供应商和生产厂家的右键菜单功能
    @pyqtSlot(QPoint)
    def on_treeWidget_stuffsupplyer_customContextMenuRequested(self, pos):
        # 返回调用者的对象
        current_item = self.treeWidget_stuffsupplyer.currentItem()
        menu = QMenu()
        button1 = menu.addAction("增加")
        button2 = menu.addAction("修改")
        button3 = menu.addAction("删除")
        button4 = menu.addAction("复制")
        button5 = menu.addAction("黏贴")
        global_pos = self.treeWidget_stuffsupplyer.mapToGlobal(pos)
        action = menu.exec(global_pos)
        # 增加
        if action == button1:
            detail = StuffSupplyerModule(sdid=self.autoid, parent=self)
            detail.accepted.connect(self.get_stuffsupplyer)
            detail.show()
        # 修改
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = StuffSupplyerModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_stuffsupplyer)
            detail.show()
        # 删除
        elif action == button3:
            select_item = self.treeWidget_stuffsupplyer.selectedItems()
            item_autoid = []
            for item in select_item:
                item_autoid.append(int(item.text(0)))
            self.SPC.delete_data(1, *item_autoid)
            self.get_stuffsupplyer()
        # 复制
        elif action == button4:
            clipboard = QApplication.clipboard()
            # 当前选择的项目
            items = self.treeWidget_stuffsupplyer.selectedItems()
            # 把项目转为Mime对象
            select_item = self.treeWidget_stuffsupplyer.mimeData(items)
            # 把Mime对象存入剪切板
            clipboard.setMimeData(select_item)
        # 黏贴
        elif action == button5:
            clipboard = QApplication.clipboard()
            # 获取剪切板里的内容
            data = clipboard.mimeData()
            # 获取当前行数,加1即为新的行号
            count = self.treeWidget_stuffsupplyer.topLevelItemCount()
            # dropMineData,把Mime对象转回Qtreeitem
            # 第一个参数:要添加到的父节点
            # 第二个参数:行号
            # 第三个参数:Mime数据
            res = self.treeWidget_stuffsupplyer.dropMimeData(
                self.treeWidget_stuffsupplyer.invisibleRootItem(), count + 1,
                data, Qt.CopyAction)
            # 黏贴完成后的行数
            finnal_index = self.treeWidget_stuffsupplyer.topLevelItemCount()
            if res:
                # 把黏贴的数据加入数据库中
                # 数据从count到finnal_index即为黏贴的行号
                while count < finnal_index:
                    tree_item = self.treeWidget_stuffsupplyer.topLevelItem(
                        count)
                    if tree_item is None:
                        return
                    condition = {'autoid': int(tree_item.text(0))}
                    res = self.SPC.get_data(1, **condition)
                    if len(res) != 1:
                        return
                    ori_data = res[0]
                    detail = dict()
                    detail["spid_id"] = ori_data.spid_id
                    detail["producer"] = ori_data.producer
                    detail["sdid_id"] = self.autoid
                    self.SPC.update_data(1, **detail)
                    count += 1
            self.get_stuffsupplyer()
        else:
            pass

    # 修改种类时触发
    @pyqtSlot(int)
    def on_comboBox_stufftype_currentIndexChanged(self, p_int):
        try:
            if p_int != int(self.ori_detail['stufftype']):
                self.new_detail['stufftype'] = p_int
            else:
                try:
                    del self.new_detail['stufftype']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['stufftype'] = p_int

    # 修改编号时触发
    @pyqtSlot(str)
    def on_lineEdit_stuffid_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['stuffid']:
                self.new_detail['stuffid'] = p_str
            else:
                try:
                    del self.new_detail['stuffid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['stuffid'] = p_str

    # 修改名称时触发
    @pyqtSlot(str)
    def on_lineEdit_stuffname_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['stuffname']:
                self.new_detail['stuffname'] = p_str
                self.lineEdit_inputcode.setText(
                    Inputcode.make_inputcode(p_str))
                self.lineEdit_kind.setText(p_str)
            else:
                try:
                    del self.new_detail['stuffname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['stuffname'] = p_str

    # 修改种类时触发
    @pyqtSlot(str)
    def on_lineEdit_kind_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['kind']:
                self.new_detail['kind'] = p_str
            else:
                try:
                    del self.new_detail['kind']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['kind'] = p_str

    # 修改批准文号时触发
    @pyqtSlot(str)
    def on_lineEdit_allowno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['allowno']:
                self.new_detail['allowno'] = p_str
            else:
                try:
                    del self.new_detail['allowno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['allowno'] = p_str

    # 修改输入码时触发
    @pyqtSlot(str)
    def on_lineEdit_inputcode_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['inputcode']:
                self.new_detail['inputcode'] = p_str
            else:
                try:
                    del self.new_detail['inputcode']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['inputcode'] = p_str

    # 修改含量规格时触发
    @pyqtSlot(str)
    def on_lineEdit_spec_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['spec']:
                self.new_detail['spec'] = p_str
            else:
                try:
                    del self.new_detail['spec']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['spec'] = p_str

    # 修改包装级别时触发
    @pyqtSlot(int)
    def on_comboBox_packageLv_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail['packagelv']:
                self.new_detail['packagelv'] = p_int
            else:
                try:
                    del self.new_detail['packagelv']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['packagelv'] = p_int

    # 修改包装情况时触发
    @pyqtSlot()
    def on_lineEdit_package_editingFinished(self):
        p_str = self.lineEdit_package.text()
        try:
            if p_str != self.ori_detail['package']:
                if self.set_package_rate(p_str):
                    self.new_detail['package'] = p_str
            else:
                try:
                    del self.new_detail['package']
                except KeyError:
                    pass
        except KeyError:
            if self.set_package_rate(p_str):
                self.new_detail['package'] = p_str

    def set_package_rate(self, package):
        lv = self.comboBox_packageLv.currentIndex() + 1
        items = re.split(r'\*|×|x|X', package)
        if len(items) != lv:
            msg = MessageBox(title="错误1!", informative="包装比例错误!")
            msg.exec()
            return False
        num_tuple = ('basicamount', 'spamount', 'mpamount')
        unit_tuple = ('basicunit', 'spunit', 'mpunit', 'bpunit')
        try:
            for i in range(len(items)):
                values = re.findall(r'\d+|\w+', items[i])
                self.new_detail[num_tuple[i]] = values[0]
                self.new_detail[unit_tuple[i]] = values[1]
            self.new_detail[unit_tuple[i + 1]] = values[2]
            return True
        except:
            msg = MessageBox(title="错误2!", informative="包装比例错误!")
            msg.exec()
            return False

    # 修改入库单位时触发
    @pyqtSlot(str)
    def on_comboBox_midcheckunit_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['midcheckunit']:
                self.new_detail['midcheckunit'] = p_str
            else:
                try:
                    del self.new_detail['midcheckunit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['midcheckunit'] = p_str

    # 修改取样单位时触发
    @pyqtSlot(str)
    def on_comboBox_prodcheckunit_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['prodcheckunit']:
                self.new_detail['prodcheckunit'] = p_str
            else:
                try:
                    del self.new_detail['prodcheckunit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['prodcheckunit'] = p_str

    # 修改库存上限时触发
    @pyqtSlot(str)
    def on_lineEdit_upperlimit_textChanged(self, p_str):
        p_int = float(p_str)
        try:
            if p_int != self.ori_detail['upperlimit']:
                self.new_detail['upperlimit'] = p_int
            else:
                try:
                    del self.new_detail['upperlimit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['upperlimit'] = p_int

    # 修改库存下限时触发
    @pyqtSlot(str)
    def on_lineEdit_lowlimit_textChanged(self, p_str):
        p_int = float(p_str)
        try:
            if p_int != self.ori_detail['lowlimit']:
                self.new_detail['lowlimit'] = p_int
            else:
                try:
                    del self.new_detail['lowlimit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['lowlimit'] = p_int

    # 修改复检天数时触发
    @pyqtSlot(str)
    def on_lineEdit_recheck_textChanged(self, p_str):
        p_int = int(p_str)
        try:
            if p_int != self.ori_detail['countercheckdays']:
                self.new_detail['countercheckdays'] = p_int
            else:
                try:
                    del self.new_detail['countercheckdays']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['countercheckdays'] = p_int

    # 修改有效期时触发
    @pyqtSlot(str)
    def on_lineEdit_expired_textChanged(self, p_str):
        p_int = int(p_str)
        try:
            if p_int != self.ori_detail['expireddays']:
                self.new_detail['expireddays'] = p_int
            else:
                try:
                    del self.new_detail['expireddays']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['expireddays'] = p_int

    # 修改效价单位时触发
    @pyqtSlot(str)
    def on_lineEdit_cunit_textChanged(self, p_int):
        try:
            if p_int != self.ori_detail['cunit']:
                self.new_detail['cunit'] = p_int
            else:
                try:
                    del self.new_detail['cunit']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['cunit'] = p_int

    # 修改储存条件时触发
    @pyqtSlot(str)
    def on_lineEdit_storage_textChanged(self, p_int):
        try:
            if p_int != self.ori_detail['storage']:
                self.new_detail['storage'] = p_int
            else:
                try:
                    del self.new_detail['storage']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['storage'] = p_int

    # 修改生产线和车间时触发
    @pyqtSlot()
    def on_toolButton_workshop_clicked(self):
        setpl = SetProductLine(parent=self, pltype=1)
        setpl.select_line_signal.connect(self.setproductline)
        setpl.show()

    def setproductline(self, linedetail: dict):
        try:
            if linedetail['autoid'] != self.ori_detail['plid']:
                self.new_detail['plid'] = linedetail['autoid']
                self.toolButton_workshop.setText(linedetail['deptname'])
                self.label_productionline.setText(linedetail['linename'])
            else:
                try:
                    del self.new_detail['plid']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['plid'] = linedetail['autoid']
            self.toolButton_workshop.setText(linedetail['deptname'])
            self.label_productionline.setText(linedetail['linename'])

    # 确认
    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if len(self.new_detail):
            if self.autoid is None:
                res = self.SC.update_data(0, **self.new_detail)
                self.autoid = res.autoid
            else:
                condition = {'autoiod': self.autoid}
                self.SC.update_data(0, condition, **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()
예제 #20
0
class SupplyerListModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(SupplyerListModule, self).__init__(parent)
        self.setupUi(self)
        if '3' not in user.powers:
            self.close()
        if user.powers['3'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['3'])
        self.SC = SupplyerController()
        self.IC = ImageController()
        self.kind_list = []
        self.curremt_kind = 0
        self.treeWidget_kind.hideColumn(1)
        self.treeWidget_detail.hideColumn(0)
        self.get_kind_list()
        self.get_supplyer_list()

    def get_kind_list(self):
        self.treeWidget_kind.clear()
        key_dict = {'kind': 0}
        self.kind_list = self.SC.get_data(5, False, *VALUES_TUPLE_KIND,
                                          **key_dict)
        # if not len(self.kind_list):
        #     return
        self.set_kind_list(self.kind_list)
        # self.treeWidget_kind.resizeColumnToContents(0)
        self.treeWidget_kind.expandAll()

    def set_kind_list(self, items):
        qtreeitem_all = QTreeWidgetItem(self.treeWidget_kind)
        qtreeitem_all.setText(0, "全部")
        qtreeitem_all.setText(1, "0")
        for item in items:
            res = self.treeWidget_kind.findItems(str(item['autoid']),
                                                 Qt.MatchRecursive, 1)
            if len(res):
                continue
            if item['parentid'] != 0:
                parent_item = self.find_kind_item(item['parentid'])
                qtreeitem = QTreeWidgetItem(parent_item)
            else:
                qtreeitem = QTreeWidgetItem(qtreeitem_all)
            qtreeitem.setText(0, item['kindname'])
            qtreeitem.setText(1, str(item['autoid']))

    def find_kind_item(self, parentid, i=0):
        res = self.treeWidget_kind.findItems(str(parentid), Qt.MatchRecursive,
                                             1)
        if len(res):
            return res[0]
        else:
            parent = self.treeWidget_kind.topLevelItem(0)
            try:
                if i > 10:
                    # 手动设置最大循环深度位10
                    raise RecursionError
                for item in self.kind_list:
                    if item['autoid'] == parentid:
                        parent_id = item['parentid']
                        if parent_id == 0:
                            parent = QTreeWidgetItem(
                                self.treeWidget_kind.topLevelItem(0))
                            parent.setText(0, item['kindname'])
                            parent.setText(1, str(item['autoid']))
                            break
                        else:
                            i += 1
                            parent = self.find_kind_item(parent_id, i)
                            break
                return parent
            except RecursionError:
                return parent

    def get_supplyer_list(self):
        self.treeWidget_detail.clear()
        key_dict = dict()
        if self.curremt_kind != 0:
            key_dict['tstkind'] = self.curremt_kind
        res = self.SC.get_data(0, False, *VALUES_TUPLE_SP, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_detail)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['supid'])
            qtreeitem.setText(2, item['supname'])
            qtreeitem.setText(3, item['address'])
            qtreeitem.setText(4, item['charger'])
            qtreeitem.setText(5, item['telno'])
            qtreeitem.setText(6, item['taxno'])
        for i in range(1, 7):
            self.treeWidget_detail.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemClicked(self, qtreeitem, p_int):
        self.curremt_kind = int(qtreeitem.text(1))
        self.get_supplyer_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_detail_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        id = int(qtreeitem.text(0))
        detail = EditSupplyerDetailModule(id, self)
        detail.accepted.connect(self.get_supplyer_list)
        detail.show()

    @pyqtSlot(QPoint)
    def on_treeWidget_kind_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        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:
            if current_item is None:
                parent_item = self.treeWidget_kind.topLevelItem(0)
            else:
                parent_item = current_item
            parent_id = int(parent_item.text(1))
            kwargs = {
                'kind': 0,
                'kindname': "新建分类",
                'parentid': parent_id,
                'inputcode': Inputcode.make_inputcode("新建分类")
            }
            kind_object = self.SC.update_data(5, **kwargs)
            qtreeitem = QTreeWidgetItem(parent_item)
            qtreeitem.setText(0, "新建分类")
            qtreeitem.setText(1, str(kind_object.autoid))

            self.treeWidget_kind.openPersistentEditor(qtreeitem, 0)
            self.treeWidget_kind.setCurrentItem(qtreeitem)
        elif action == button2:
            if current_item is None:
                return
            self.treeWidget_kind.setCurrentItem(None)
            self.treeWidget_kind.openPersistentEditor(current_item, 0)
            self.treeWidget_kind.setCurrentItem(current_item, 0)

        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(1))
            condition = {'autoid': id}
            self.SC.delete_data(5, condition)
            self.get_kind_list()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemChanged(self, qtreeitem, p_int):
        if self.treeWidget_kind.isPersistentEditorOpen(qtreeitem, p_int):
            self.treeWidget_kind.closePersistentEditor(qtreeitem, p_int)
            id = int(qtreeitem.text(1))
            new_kindname = qtreeitem.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.SC.update_data(5, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
    def on_treeWidget_kind_currentItemChanged(self, qtreeitem, qtreeitem_1):
        if self.treeWidget_kind.isPersistentEditorOpen(qtreeitem_1, 0):
            self.treeWidget_kind.closePersistentEditor(qtreeitem_1, 0)
            id = int(qtreeitem_1.text(1))
            new_kindname = qtreeitem_1.text(0)
            condition = {'autoid': id}
            kwargs = {'kindname': new_kindname}
            self.SC.update_data(5, condition, **kwargs)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_kind_itemDoubleClicked(self, qtreeitem, p_int):
        self.treeWidget_kind.openPersistentEditor(qtreeitem, p_int)

    @pyqtSlot(QPoint)
    def on_treeWidget_detail_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        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 = EditSupplyerDetailModule(parent=self)
            detail.accepted.connect(self.get_supplyer_list)
            detail.show()
        elif action == button2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = EditSupplyerDetailModule(id, self)
            detail.accepted.connect(self.get_supplyer_list)
            detail.show()
        elif action == button3:
            if current_item is None:
                return
            id = int(current_item.text(0))
            condition = {'autoid': id}
            condition_2 = {'spid': id}
            condition_3 = {'scid': id, 'kind': 0}
            self.SC.delete_data(4, condition_2)
            self.SC.delete_data(0, condition)
            img_id_list = self.IC.get_data(0, True, *VALUES_TUPLE_IM,
                                           **condition_3)
            condition_4 = {'autoid__in': img_id_list}
            self.IC.delete_data(1, condition_4)
            self.IC.delete_data(0, condition_3)
            self.get_supplyer_list()
예제 #21
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)
예제 #22
0
class EditpurstuffModule(QDialog, Ui_Dialog):
    def __init__(self, spid, ppid=None, autoid=None, parent=None):
        super(EditpurstuffModule, self).__init__(parent)
        self.ori_detail = dict()
        self.new_detail = dict()
        self.SC = SupplyerController()
        self.SFC = StuffController()
        self.setupUi(self)
        # row = ('autoid', 'stuffid', 'stuffname', 'spec', 'package')
        # key = ('stuffid', 'stuffname', 'stuffkind', 'inputcode')
        # row_name = ('id', '物料编号', '物料名称', '含量规格', '包装规格')
        # self.lineEdit_supplyer.setup('Supplyer', row, key, row_name, 539, 240)

        self.autoid = autoid
        self.spid = spid
        self.ppid = ppid

        self.get_detail()
        self.set_amount_validator()

    def get_detail(self):
        if not self.autoid:
            return
        key_dict = {'autoid': self.autoid}
        res = self.SC.get_purchstuff(False, *VALUES_TUPLE_PPLIST, **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'])

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

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

    @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.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.new_detail['expireddays'] = stuff['expireddays']
        self.lineEdit_amount.setFocus()

    @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 len(text) > 0:
            message = MessageBox(self, text="以下信息填写错误", informative=text)
            message.show()
            return
        if len(self.new_detail):
            if self.ppid:
                self.new_detail['ppid'] = self.ppid
            res = self.SC.update_purchstuff(self.autoid, **self.new_detail)
            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
예제 #23
0
class StuffSupplyerModule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, sdid=None, parent=None):
        super(StuffSupplyerModule, self).__init__(parent)
        self.setupUi(self)
        # 修改前数据,若为新建则为空
        self.ori_detail = object
        # 修改后的数据,自动把修改过的数据添加到字典中,
        # 若恢复原来的数据或者删除,则字典中也删除
        self.new_detail = {}
        # 物料字典中的autoid,由生成界面时传入
        self.sdid = sdid
        # 物料供应商的autoid,仅修改记录时才有值传入
        self.autoid = autoid
        # 数据库操作类
        self.SC = SupplyerController()
        return_row = ('autoid', 'supid', 'supname')
        condition_key = ('supid', 'supname', 'inputcode')
        treeheader_name = ["id", "编号", "名称"]
        self.lineEdit_supplyer.setup(
            'Supplyer', return_row, condition_key, treeheader_name, None,
            500, 180
        )
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            return
        condition = {'autoid': self.autoid}
        res = self.SC.get_data(1, False, **condition)
        if len(res) != 1:
            return
        self.ori_detail = res[0]
        self.lineEdit_supplyer.setText(
            self.ori_detail.spid.supid + ' ' + self.ori_detail.spid.supname
        )
        self.lineEdit_producer.setText(self.ori_detail.producer)

    @pyqtSlot(object)
    def on_lineEdit_supplyer_getItem(self, qtreeitem):
        spid = int(qtreeitem.text(0))
        try:
            if spid != self.ori_detail.spid_id:
                self.new_detail['spid_id'] = spid
            else:
                try:
                    del self.new_detail['spid_id']
                except KeyError:
                    pass
        except (KeyError, AttributeError):
            self.new_detail['spid_id'] = spid

    @pyqtSlot(str)
    def on_lineEdit_producer_textChanged(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, AttributeError):
            self.new_detail['producer'] = p_str

    # 确认
    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        # autoid不为空,则为修改记录
        # 否则为插入记录
        if self.autoid:
            condition = {'autoid': self.autoid}
            self.SC.update_data(1, condition, **self.new_detail)
        else:
            # 把sdid加到更新内容里
            if self.sdid:
                self.new_detail['sdid_id'] = self.sdid
                self.SC.update_data(1, **self.new_detail)
        self.accept()

    # 取消
    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
예제 #24
0
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 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()