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()
Exemple #2
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()
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()