Пример #1
0
class StuffRepositoryModule(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(StuffRepositoryModule, self).__init__(parent)
        self.setupUi(self)

        if '41' not in user.powers:
            self.close()
        if user.powers['41'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['41'])

        self.WC = WarehouseController()
        self.CI = CheckItem()
        self.LC = LabrecordsController()
        self.SFC = StuffController()
        self.current_button = self.radioButton_batchno
        self.get_stuff_list()

    def get_stuff_list(self):
        if self.current_button == self.radioButton_batchno:
            values_tuple = VALUES_TUPLE_BATCHNO
            self.treeWidget_stuffbatchnolist.setVisible(True)
            self.treeWidget_stuffkindlist.setVisible(False)
            current_tree = self.treeWidget_stuffbatchnolist
            current_tree.hideColumn(0)
            current_tree.hideColumn(1)
        elif self.current_button == self.radioButton_kind:
            values_tuple = VALUES_TUPLE_KIND
            self.treeWidget_stuffbatchnolist.setVisible(False)
            self.treeWidget_stuffkindlist.setVisible(True)
            current_tree = self.treeWidget_stuffkindlist
        else:
            return

        current_tree.clear()
        index = self.tabWidget.currentIndex()
        key_dict = {'amount__gt': 0}
        if index != 0:
            key_dict['stufftype'] = index - 1
        stuff_list = self.WC.get_stuffrepository(False, *values_tuple,
                                                 **key_dict)
        if not len(stuff_list):
            return
        if current_tree == self.treeWidget_stuffbatchnolist:
            self.set_batchno_tree(current_tree, stuff_list)
            for i in range(2, 25):
                current_tree.resizeColumnToContents(i)
        elif current_tree == self.treeWidget_stuffkindlist:
            self.set_kind_tree(current_tree, stuff_list)
            for i in range(0, 3):
                current_tree.resizeColumnToContents(i)
        else:
            return

    def set_batchno_tree(self, current_tree, stuff_list):
        for item in stuff_list:
            qtreeitem = QTreeWidgetItem(current_tree)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, str(item['lrid']))
            qtreeitem.setText(2, STATUS[item['status']])
            qtreeitem.setText(3, item['stuffid'] + ' ' + item['stuffname'])
            qtreeitem.setText(4, item['stuffkind'])
            qtreeitem.setText(5, STUFF_KIND[item['stufftype']])
            qtreeitem.setText(6, item['batchno'])
            qtreeitem.setText(7, item['mbatchno'])
            qtreeitem.setText(8, item['spec'])
            qtreeitem.setText(9, item['package'])
            qtreeitem.setText(10, str(item['piamount']))
            qtreeitem.setText(11, str(item['amount']))
            qtreeitem.setText(12, item['basicunit'])
            qtreeitem.setText(13, item['position'])
            qtreeitem.setText(14, str(item['makedate']))
            qtreeitem.setText(15, str(item['putindate']))
            qtreeitem.setText(16, str(item['expireddate']))
            qtreeitem.setText(17, str(item['nextcheckdate']))
            qtreeitem.setText(18, item['supid'] + ' ' + item['supname'])
            qtreeitem.setText(19, item['producer'])
            qtreeitem.setText(20, str(item['content']) + item['cunit'])
            qtreeitem.setText(21, str(item['water']) + '%')
            qtreeitem.setText(22, str(item['rdensity']))
            qtreeitem.setText(23, str(item['impurity']) + '%')
            qtreeitem.setText(
                24, item['warehousemanid'] + item['warehousemanname'])

    def set_kind_tree(self, current_tree, stuff_list):
        kind_list = stuff_list.annotate(amount=Sum('amount'),
                                        piamount=Sum('piamount'))
        for item in kind_list:
            qtreeitem = QTreeWidgetItem(current_tree)
            qtreeitem.setText(0, item['stuffkind'])
            qtreeitem.setText(1, str(item['piamount']))
            qtreeitem.setText(2, str(item['amount']))
            qtreeitem.setText(3, item['basicunit'])

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, p_int):
        curent_tab = getattr(self, 'tab_' + str(p_int))
        curent_tab.setLayout(self.gridLayout_2)
        self.get_stuff_list()

    pyqtSlot(bool)

    def on_radioButton_batchno_toggled(self, p_bool):
        if p_bool:
            self.current_button = self.radioButton_batchno
            self.get_stuff_list()

    pyqtSlot(bool)

    def on_radioButton_kind_toggled(self, p_bool):
        if p_bool:
            self.current_button = self.radioButton_kind
            self.get_stuff_list()

    @pyqtSlot(QPoint)
    def on_treeWidget_stuffbatchnolist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return

        id = 0
        lrid = 0
        stuffid = ''
        batchno = ''
        sender_widget = self.sender()
        current_item = sender_widget.currentItem()
        if current_item is None:
            return

        id = int(current_item.text(0))
        lrid = int(current_item.text(1))
        stuffid, stuffname = current_item.text(3).split(' ')
        batchno = current_item.text(6)

        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 = ModifyStuffParmeter(id, self)
            detail.accepted.connect(self.get_stuff_list)
            detail.show()

        elif action == button2:
            detail = FindCheckReportModule(stuffid, batchno, self)
            detail.show()

        elif action == button3:
            key_dict = {'stuffid': stuffid, 'stuffname': stuffname}
            checkunit = ''
            res = self.SFC.get_stuffdict(True, *VALUES_TUPLE_SD, **key_dict)
            if len(res):
                checkunit = res[0]
            kwargs = {
                'labtype':
                1,
                'chkid':
                stuffid,
                'chkname':
                stuffname,
                'batchno':
                current_item.text(6),
                'mbatchno':
                current_item.text(7),
                'spec':
                current_item.text(8),
                'package':
                current_item.text(9),
                'producer':
                current_item.text(19),
                'supplyer':
                current_item.text(18) if current_item.text(18) in ('', ' ')
                else current_item.text(18).split(' ')[2],
                'ciid':
                int(current_item.text(0)),
                'createdate':
                user.now_date,
                'checkamount':
                decimal.Decimal(current_item.text(11)),
                'caunit':
                current_item.text(12),
                'sampleunit':
                checkunit,
                'samplesource':
                current_item.text(13)
            }
            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)
            detail = ApplycheckModule(autoid=labrecord.autoid, parent=self)
            detail.rejected.connect(
                lambda: self.delete_check_report(labrecord.autoid))
            detail.show()

    def delete_check_report(self, lrid):
        self.LC.delete_labrecord(lrid)
        self.LC.delete_labitem(lrid)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_stuffbatchnolist_itemDoubleClicked(
            self, qtreeitem, p_int):
        if self.power[1] == '0':
            return

        id = int(qtreeitem.text(0))
        lrid = int(qtreeitem.text(1))
        detail = ModifyStuffParmeter(id, self)
        detail.accepted.connect(self.get_stuff_list)
        detail.show()
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()