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()
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()
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()
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 EditStuffCheckInModule(QDialog, Ui_Dialog): def __init__(self, autoid, lrid=0, parent=None): super(EditStuffCheckInModule, self).__init__(parent) self.ori_detail = dict() self.detail = { 'content': decimal.Decimal('-1'), 'cunit': '%', 'water': decimal.Decimal('-1'), 'rdensity': decimal.Decimal('-1'), 'impurity': decimal.Decimal('-1'), 'position': '' } self.new_detail = dict() self.LC = LabrecordsController() self.WC = WarehouseController() self.SFC = StuffController() self.setupUi(self) self.autoid = autoid self.lrid = lrid self.get_detail() if lrid != 0: self.set_putin_parameter() self.set_validator() self.get_location_list() if len(self.ori_detail): self.set_content_unit() def get_detail(self): if not self.autoid: self.pushButton_accept.setEnabled(False) return 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] def set_putin_parameter(self): key_dict = {'lrid': self.lrid} res = self.LC.get_labitem(False, *VALUES_TUPLE_LAB, **key_dict) for item in res: if item['putintype'] == 1: try: content = re.findall('\d+\.?\d?', item['labvalue'])[0] self.lineEdit_content.setText(content) except IndexError: pass elif item['putintype'] == 2: try: water = re.findall('\d+\.?\d?', item['labvalue'])[0] self.lineEdit_water.setText(water) except IndexError: pass elif item['putintype'] == 3: try: rdensity = re.findall('\d+\.?\d?', item['labvalue'])[0] self.lineEdit_rdensity.setText(rdensity) except IndexError: pass elif item['putintype'] == 4: try: impuriity = re.findall('\d+\.?\d?', item['labvalue'])[0] self.lineEdit_impurity.setText(impuriity) except IndexError: pass def set_validator(self): doubleValitor = QDoubleValidator() doubleValitor.setBottom(-1) doubleValitor.setDecimals(3) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.lineEdit_content.setValidator(doubleValitor) self.lineEdit_water.setValidator(doubleValitor) self.lineEdit_rdensity.setValidator(doubleValitor) self.lineEdit_impurity.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 set_content_unit(self): cunit = '%' stuffid = self.ori_detail['stuffid'] key_dict = {'stuffid': stuffid} stuff_list = self.SFC.get_stuffdict(False, *VALUES_TUPLE_STUFF, **key_dict) if len(stuff_list): stuff = stuff_list[0] cunit = stuff['cunit'] self.label_contentunit.setText(cunit) self.detail['cunit'] = cunit self.detail['stuffkind'] = stuff['kind'] self.detail['stufftype'] = stuff['stufftype'] self.detail['allowno'] = stuff['allowno'] self.detail['nextcheckdate'] = user.now_date + datetime.timedelta( days=stuff['countercheckdays']) self.detail['spamount'] = stuff['spamount'] self.detail['spunit'] = stuff['spunit'] self.detail['basicamount'] = stuff['basicamount'] @pyqtSlot(str) def on_lineEdit_content_textChanged(self, p_str): self.detail['content'] = decimal.Decimal(p_str) @pyqtSlot(str) def on_lineEdit_water_textChanged(self, p_str): self.detail['water'] = decimal.Decimal(p_str) @pyqtSlot(str) def on_lineEdit_rdensity_textChanged(self, p_str): self.detail['rdensity'] = decimal.Decimal(p_str) @pyqtSlot(str) def on_lineEdit_impurity_textChanged(self, p_str): self.detail['impurity'] = decimal.Decimal(p_str) @pyqtSlot(str) def on_comboBox_location_currentTextChanged(self, p_str): self.detail['position'] = p_str @pyqtSlot() def on_pushButton_accept_clicked(self): self.detail['ciid'] = self.ori_detail['autoid'] self.detail['pltype'] = 0 self.detail['stuffid'] = self.ori_detail['stuffid'] self.detail['stuffname'] = self.ori_detail['stuffname'] self.detail['spec'] = self.ori_detail['spec'] self.detail['package'] = self.ori_detail['package'] self.detail['supid'] = self.ori_detail['supid'] self.detail['supname'] = self.ori_detail['supname'] self.detail['producer'] = self.ori_detail['producer'] self.detail['makedate'] = self.ori_detail['makedate'] self.detail['batchno'] = self.ori_detail['batchno'] self.detail['mbatchno'] = self.ori_detail['mbatchno'] self.detail['expireddate'] = self.ori_detail['expireddate'] self.detail['amount'] = self.ori_detail['amount'] self.detail['piamount'] = self.ori_detail['amount'] self.detail['basicunit'] = self.ori_detail['unit'] self.detail['checkindate'] = self.ori_detail['checkindate'] self.detail['putindate'] = user.now_date self.detail['lrid'] = self.ori_detail['lrid'] self.detail['warehousemanid'] = user.user_id self.detail['warehousemanname'] = user.user_name res = self.WC.update_stuffrepository(**self.detail) srid_id = res.autoid cil_detail = { 'status': 5, 'srid': srid_id, 'pidate': user.now_date, 'content': self.detail['content'], 'cunit': self.detail['cunit'], 'water': self.detail['water'], 'rdensity': self.detail['rdensity'], 'impurity': self.detail['impurity'] } self.WC.update_stuffcheckinlist(self.autoid, **cil_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class PreProdPutInModule(QWidget, Ui_Form): accepted = pyqtSignal() def __init__(self, autoid: int = 0, ppid: int = 0, parent=None): super(PreProdPutInModule, self).__init__(parent) self.setupUi(self) self.ppid = ppid self.autoid = autoid self.content = decimal.Decimal('-1') self.water = decimal.Decimal('-1') self.rdensity = decimal.Decimal('-1') self.impurity = decimal.Decimal('-1') self.lrid = 0 self.checkdate = user.now_date # self.units = set() self.unit = '' self.cunit = '%' self.expireddays = 730 self.countercheckdays = 365 self.WC = WorkshopController() self.LC = LabrecordsController() self.PC = ProductController() self.SC = StuffController() self.product_detail = dict() self.ori_detail = dict() self.new_detail = dict() # 把autoid和ppid补全 self.get_autoid_or_ppid() # 获取入库位置的下拉选项 self.get_postiton() # 整箱数量的校验器 self.set_valitor(self.lineEdit_amount, 0) # 获取产品信息 self.get_productdetail() # 设置含量单位、复检日期、有效期等参数 self.basicdetail() # 获取报告书的状态和编号 self.get_labdetail() # 获取入库信息 self.get_putinnote() def get_autoid_or_ppid(self): values_list = ('autoid', 'ppid') if self.autoid: key_dict = {'autoid': self.autoid} else: key_dict = {'ppid': self.ppid} res = self.WC.get_productputinnote(False, *values_list, **key_dict) if not len(res): return if self.autoid: self.ppidid = res[0]['ppid'] else: self.autoid = res[0]['autoid'] def set_valitor(self, widget, bottom=0, top=0): intvalitor = QIntValidator() intvalitor.setBottom(bottom) if top != 0: intvalitor.setTop(top) widget.setValidator(intvalitor) def get_postiton(self): key_dict_ws = {'ppid': self.ppid} ws_list = self.WC.get_productputinnote(True, *VALUES_LIST_WS, **key_dict_ws) if not len(ws_list): return warehouseid = ws_list[0] values_list_positon = ('position', ) key_dict_position = {'warehouseid': warehouseid} pos_list = self.WC.get_productputinnote(True, *values_list_positon, **key_dict_position) if len(pos_list): self.comboBox_piposition.addItems(pos_list.distinct()) def get_productdetail(self): key_dict = {'autoid': self.ppid} res = self.PC.get_producingplan(False, *VALUES_LIST_PROD, **key_dict) if len(res) != 1: return self.product_detail = res[0] self.label_product.setText( self.product_detail['prodid'] + ' ' + \ self.product_detail['prodname'] ) self.label_spec.setText(self.product_detail['spec']) self.label_package.setText(self.product_detail['package']) self.label_unit.setText(self.product_detail['basicunit']) def basicdetail(self): if not len(self.product_detail): return stuffid = self.product_detail['prodid'] stuffname = self.product_detail['prodname'] key_dict = {'stuffid': stuffid, 'stuffname': stuffname} res = self.SC.get_stuffdict(False, *VALUES_TUPLE_STUFF, **key_dict) if not len(res): return self.cunit = res[0]['cunit'] self.expireddays = res[0]['expireddays'] self.countercheckdays = res[0]['countercheckdays'] self.label_contentunit.setText(self.cunit) def get_labdetail(self): values_list = ('autoid', 'paperno', 'status', 'reportdate') key_dict = {'labtype': 2, 'ciid': self.ppid} res = self.LC.get_labrecord(False, *values_list, **key_dict) if not len(res): return # 选择最后一条符合条件的成品报告 detail = res.order_by('-autoid')[0] self.lrid = detail['autoid'] self.checkdate = detail['reportdate'] self.label_reportpaperno.setText(detail['paperno']) self.label_checkstatus.setText(CHECK_STATUS[detail['status']]) def get_putinnote(self): key_dict = {'autoid': self.autoid} res = self.WC.get_productputinnote(False, *VALUES_TUPLE_PUTIN, **key_dict) if not len(res): return # 选择第一条 self.ori_detail = res[0] self.label_warehouse.setText(self.ori_detail['warehouseid'] + ' ' + self.ori_detail['warehousename']) self.comboBox_piposition.setCurrentText(self.ori_detail['position']) self.pushButton_applyer.setText(self.ori_detail['piapplyerid'] + ' ' + self.ori_detail['piapplyername']) self.pushButton_qa.setSign( True, self.ori_detail['piqaid'] + ' ' + self.ori_detail['piqaname']) self.pushButton_piwsman.setSign( True, self.ori_detail['warehousemanid'] + ' ' + self.ori_detail['warehousemanname']) self.lineEdit_amount.setText(to_str(self.ori_detail['piamount'])) if self.ori_detail['pistatus'] == 0: self.pushButton_accept.setVisible(True) self.pushButton_save.setVisible(True) self.pushButton_cancel.setVisible(False) self.pushButton_pi.setVisible(False) elif self.ori_detail['pistatus'] == 1: self.pushButton_accept.setVisible(False) self.pushButton_save.setVisible(False) self.pushButton_cancel.setVisible(True) self.pushButton_pi.setVisible(True) elif self.ori_detail['pistatus'] == 3: self.pushButton_accept.setVisible(False) self.pushButton_save.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_pi.setVisible(False) @pyqtSlot(str) def on_lineEdit_amount_textEdited(self, p_str): if p_str == '': amount = decimal.Decimal('0') else: amount = decimal.Decimal(p_str) try: if amount != self.ori_detail['piamount']: self.new_detail['piamount'] = amount else: try: del self.new_detail['piamount'] except KeyError: pass except KeyError: self.new_detail['piamount'] = amount @pyqtSlot(bool, str) def on_pushButton_qa_signChanged(self, p_bool, p_str): if p_bool: self.pushButton_accept.setEnabled(True) piqaid, piqaname = p_str.split(' ') else: self.pushButton_accept.setEnabled(False) piqaid, piqaname = ('', '') try: if piqaid != self.ori_detail['piqaid']: self.new_detail['piqaid'] = piqaid self.new_detail['piqaname'] = piqaname else: try: del self.new_detail['piqaid'] del self.new_detail['piqaname'] except KeyError: pass except KeyError: self.new_detail['piqaid'] = piqaid self.new_detail['piqaname'] = piqaname @pyqtSlot(bool, str) def on_pushButton_applyer_signChanged(self, p_bool, p_str): if p_bool: piapplyerid, piapplyername = p_str.split(' ') else: piapplyerid, piapplyername = ('', '') try: if piapplyerid != self.ori_detail['piapplyerid']: self.new_detail['piapplyerid'] = piapplyerid self.new_detail['piapplyername'] = piapplyername else: try: del self.new_detail['piapplyerid'] del self.new_detail['piapplyername'] except KeyError: pass except KeyError: self.new_detail['piapplyerid'] = piapplyerid self.new_detail['piapplyername'] = piapplyername @pyqtSlot(str) def on_comboBox_piposition_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() def on_pushButton_save_clicked(self): if self.has_changed(): self.WC.update_productputinnote(self.autoid, **self.new_detail) @pyqtSlot() def on_pushButton_accept_clicked(self): if self.lineEdit_amount.text() in ('', '0'): msg = MessageBox(self, text="入库数量不能未空") msg.show() return if self.pushButton_applyer.text() in ('', ' '): self.pushButton_applyer.setSign( True, user.user_id + ' ' + user.user_name) self.new_detail['piapplyerid'] = user.user_id self.new_detail['piapplyername'] = user.user_name self.new_detail['pidate'] = user.now_date self.new_detail['pistatus'] = 1 self.WC.update_productputinnote(self.autoid, **self.new_detail) realamount = decimal.Decimal(self.lineEdit_amount.text()) detail = {'realamount': realamount} self.PC.update_producingplan(self.ppid, **detail) self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(True) self.pushButton_pi.setVisible(True) self.accepted.emit() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.new_detail['piapplyerid'] = '' self.new_detail['piapplyername'] = '' self.new_detail['pistatus'] = 0 self.WC.update_productputinnote(self.autoid, **self.new_detail) self.pushButton_save.setVisible(True) self.pushButton_accept.setVisible(True) self.pushButton_cancel.setVisible(False) self.pushButton_pi.setVisible(False) self.accepted.emit() @pyqtSlot() def on_pushButton_pi_clicked(self): if self.label_checkstatus.text() != '检验合格': mesgbox = MessageBox(parent=self, title="提示", text="当前产品尚未检验合格无法入库") mesgbox.exec() return self.new_detail['warehousemanid'] = user.user_id self.new_detail['warehousemanname'] = user.user_name self.new_detail['pidate'] = user.now_date self.new_detail['pistatus'] = 3 # 计算要入库的产品信息 putin_msg = self.get_putin_msg() res = self.WC.update_preproductputinnote(self.autoid, putin_msg, **self.new_detail) if not res: return self.pushButton_piwsman.setSign(True, user.user_id + ' ' + user.user_name) self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_pi.setVisible(False) self.accepted.emit() def get_putin_msg(self): return_dict = self.product_detail return_dict['stuffid'] = return_dict.pop('prodid') return_dict['stuffname'] = return_dict.pop('prodname') return_dict['stuffkind'] = return_dict.pop('commonname') return_dict['ciid'] = self.autoid return_dict['pltype'] = 1 return_dict['stufftype'] = 1 return_dict['expireddate'] = self.product_detail['makedate'] + \ datetime.timedelta(days=self.expireddays) return_dict['amount'] = decimal.Decimal(self.lineEdit_amount.text()) return_dict['piamount'] = decimal.Decimal(self.lineEdit_amount.text()) return_dict['position'] = self.comboBox_piposition.currentText() return_dict['checkindate'] = user.now_date return_dict['putindate'] = user.now_date return_dict['warehousemanid'] = user.user_id return_dict['warehousemanname'] = user.user_name return_dict['content'] = self.content return_dict['cunit'] = self.cunit return_dict['water'] = self.water return_dict['rdensity'] = self.rdensity return_dict['impurity'] = self.impurity return_dict['lrid'] = self.lrid return_dict['checkdate'] = self.checkdate return_dict['nextcheckdate'] = self.checkdate + \ datetime.timedelta(days=self.countercheckdays) return_dict['deptid'] = self.ori_detail['warehouseid'] return_dict['deptname'] = self.ori_detail['warehousename'] return return_dict def has_changed(self): if not len(self.new_detail): return False if self.pushButton_applyer.text() in ('', ' '): self.pushButton_applyer.setSign( True, user.user_id + ' ' + user.user_name) self.new_detail['piapplyerid'] = user.user_id self.new_detail['piapplyername'] = user.user_name return True