class ProductputinModule(QWidget, Ui_Form): accepted = pyqtSignal() def __init__(self, autoid:int=0, ppid: int=0, parent=None): super(ProductputinModule, self).__init__(parent) self.setupUi(self) self.ppid = ppid self.autoid = autoid self.bpamount = decimal.Decimal('0') self.mpamount = decimal.Decimal('0') self.spamount = decimal.Decimal('0') self.a_box_samount = decimal.Decimal('0') self.oddments_list = [] self.units = set() self.WC = WorkshopController() self.LC = LabrecordsController() self.PC = ProductController() self.product_detail = dict() self.ori_detail = dict() self.new_detail = dict() if not self.ppid and not self.autoid: return # 把autoid和ppid补全 self.get_autoid_or_ppid() # 获取产品信息 self.get_productdetail() # 设置比例、一箱数量等参数 self.basicdetail() # 获取寄库和入库位置的下拉选项 self.get_postiton() # 获取报告书的状态和编号 self.get_labdetail() # 获取入库信息 self.get_putinnote() # 获取零头领取信息 self.get_oddment() # 整箱数量的校验器 self.set_valitor(self.lineEdit_amount, 0) # 零头数量的校验器 self.set_valitor(self.lineEdit_oddment, 0, self.a_box_samount) self.set_total_amount() 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 self.autoid = res[0]['autoid'] self.ppid = res[0]['ppid'] 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): values_list_ws = ("warehouseid",) 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_dppositon = ('dpposition',) values_list_positon = ('position',) key_dict_position = { 'warehouseid': warehouseid } dppos_list = self.WC.get_productputinnote( True, *values_list_dppositon, **key_dict_position) pos_list = self.WC.get_productputinnote( True, *values_list_positon, **key_dict_position) if len(dppos_list): self.comboBox_dpposition.addItems(dppos_list.distinct()) if len(pos_list): self.comboBox_piposition.addItems(pos_list.distinct()) def get_productdetail(self): VALUES_LIST = ( "prodid", "prodname", "spec", "package", "bpamount", "bpunit", "mpamount", "mpunit", "spamount", "spunit", "lpunit" ) key_dict = { 'autoid': self.ppid } res = self.PC.get_producingplan( False, *VALUES_LIST, **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_piunit.setText(self.product_detail['spunit']) self.label_dpunit.setText(self.product_detail['spunit']) def basicdetail(self): if self.product_detail['bpamount'] != decimal.Decimal('0'): self.bpamount = self.product_detail['bpamount'] else: self.bpamount = decimal.Decimal('1') if self.product_detail['mpamount'] != decimal.Decimal('0'): self.mpamount = self.product_detail['mpamount'] else: self.mpamount = decimal.Decimal('1') if self.product_detail['spamount'] != decimal.Decimal('0'): self.spamount = self.product_detail['spamount'] else: self.spamount = decimal.Decimal('1') self.a_box_samount = self.bpamount * self.mpamount * self.spamount self.units = [ self.product_detail['lpunit'], self.product_detail['bpunit'], self.product_detail['mpunit'], self.product_detail['spunit'] ] def get_labdetail(self): values_list = ("paperno", "status") key_dict = { 'labtype': 4, '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.label_reportpaperno.setText(detail['paperno']) self.label_checkstatus.setText(CHECK_STATUS[detail['status']]) def get_putinnote(self): values_list = ( "dpamount", "piamount", "packamount", "unittype", "pidate", "piapplyerid", "piapplyername", "piqaid", "piqaname", "warehousemanid", "warehousemanname", "pistatus", "position", "dpposition", "dpwarehousemanid", "dpwarehousemanname", "warehouseid", "warehousename", "oddment", "dpdate", "oddment" ) key_dict = { 'autoid': self.autoid } res = self.WC.get_productputinnote( False, *values_list, **key_dict ) if not len(res): return # 选择第一条 self.ori_detail = res[0] self.label_dpdate.setText( str(self.ori_detail['dpdate']) if type(self.ori_detail['dpdate']) is datetime.date else '' ) self.label_pidate.setText( str(self.ori_detail['pidate']) if type(self.ori_detail['pidate']) is datetime.date else '' ) self.comboBox_unittype.setCurrentIndex(self.ori_detail['unittype']) self.label_warehouse.setText( self.ori_detail['warehouseid'] + ' ' + self.ori_detail['warehousename'] ) self.comboBox_dpposition.setCurrentText(self.ori_detail['dpposition']) 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_dpwsman.setText( self.ori_detail['dpwarehousemanid'] + ' ' + self.ori_detail['dpwarehousemanname'] ) self.pushButton_piwsman.setSign( True, self.ori_detail['warehousemanid'] + ' ' + self.ori_detail['warehousemanname'] ) self.lineEdit_amount.setText(str(self.ori_detail['dpamount'])) self.lineEdit_oddment.setText(str(self.ori_detail['oddment'])) self.label_unit.setText(self.units[self.ori_detail['unittype']]) self.label_oddmentunit.setText(self.units[3]) self.label_dpamount.setText(str(self.ori_detail['piamount'])) self.label_piamount.setText(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_dp.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_dp.setVisible(True) self.pushButton_pi.setVisible(False) elif self.ori_detail['pistatus'] == 2: self.pushButton_accept.setVisible(False) self.pushButton_save.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_dp.setVisible(False) 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_dp.setVisible(False) self.pushButton_pi.setVisible(False) def get_oddment(self): self.treeWidget_oddments.clear() self.treeWidget_oddments.hideColumn(0) values_list = ( "autoid", "batchno", "amount", "unit", "makedate", "ppid" ) key_dict = { 'dppid': self.ppid } res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict) if not len(res): return for item in res: if item['unit'] not in self.units: continue qtreeitem = QTreeWidgetItem(self.treeWidget_oddments) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['batchno']) qtreeitem.setText(2, str(item['amount'])) qtreeitem.setText(3, item['unit']) qtreeitem.setText(4, str(self.a_box_samount - item['amount'])) qtreeitem.setText(5, str(item['makedate'])) self.oddments_list.append( (2, self.ppid, self.a_box_samount, item['ppid'], item['amount']) ) for i in range(1, 6): self.treeWidget_oddments.resizeColumnToContents(i) if self.treeWidget_oddments.topLevelItemCount() > 0: self.checkBox_has_draw_oddments.setCheckState(2) @pyqtSlot(int) def on_comboBox_unittype_currentIndexChanged(self, p_int): self.label_unit.setText(self.units[p_int]) try: if p_int != self.ori_detail['unittype']: self.new_detail['unittype'] = p_int else: try: del self.new_detail['unittype'] except KeyError: pass except KeyError: self.new_detail['unittype'] = p_int self.set_total_amount() @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['dpamount']: self.new_detail['dpamount'] = amount else: try: del self.new_detail['dpamount'] except KeyError: pass self.set_total_amount() except KeyError: self.new_detail['dpamount'] = amount except decimal.InvalidOperation: pass def set_total_amount(self): if self.lineEdit_amount.text() != '': amount = decimal.Decimal(self.lineEdit_amount.text()) else: amount = decimal.Decimal('0') if self.lineEdit_oddment.text() != '': oddment = decimal.Decimal(self.lineEdit_oddment.text()) else: oddment = decimal.Decimal('0') unit_index = self.comboBox_unittype.currentIndex() this_batchno_amount = 0 if unit_index == 0: this_batchno_amount = amount * self.a_box_samount + oddment elif unit_index == 1: this_batchno_amount = amount * self.mpamount * self.spamount + oddment elif unit_index == 2: this_batchno_amount = amount * self.spamount + oddment elif unit_index == 3: this_batchno_amount = amount + oddment merge_amount = self.treeWidget_oddments.topLevelItemCount() * \ self.a_box_samount piamount = this_batchno_amount + merge_amount self.label_dpamount.setText(str(piamount)) self.label_piamount.setText(str(piamount)) try: if piamount != self.ori_detail['piamount']: self.new_detail['piamount'] = piamount else: try: del self.new_detail['piamount'] except KeyError: pass except KeyError: self.new_detail['piamount'] = piamount @pyqtSlot(str) def on_lineEdit_oddment_textEdited(self, p_str): if p_str == '': amount = decimal.Decimal('0') else: amount = decimal.Decimal(p_str) try: if amount != self.ori_detail['oddment']: self.new_detail['oddment'] = amount else: try: del self.new_detail['oddment'] except KeyError: pass self.set_total_amount() except KeyError: self.new_detail['oddment'] = amount except decimal.InvalidOperation: pass @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_dpposition_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['dpposition']: self.new_detail['dpposition'] = p_str else: try: del self.new_detail['dpposition'] except KeyError: pass except KeyError: self.new_detail['dpposition'] = p_str @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.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['dpdate'] = user.now_date self.new_detail['pistatus'] = 1 self.WC.update_productputinnote(self.autoid, **self.new_detail) realamount = decimal.Decimal(self.label_piamount.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_dp.setVisible(False) self.pushButton_pi.setVisible(False) 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_dp.setVisible(False) self.pushButton_pi.setVisible(False) self.accepted.emit() @pyqtSlot() def on_pushButton_dp_clicked(self): self.new_detail['dpwarehousemanid'] = user.user_id self.new_detail['dpwarehousemanname'] = user.user_name self.new_detail['pistatus'] = 2 self.WC.update_productputinnote(self.autoid, **self.new_detail) self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_dp.setVisible(False) self.pushButton_pi.setVisible(True) 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() self.WC.update_productputinnote(self.autoid, True, putin_msg, **self.new_detail) self.pushButton_save.setVisible(False) self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.pushButton_dp.setVisible(False) self.pushButton_pi.setVisible(False) self.accepted.emit() def get_putin_msg(self): return_detail = [] return_detail += self.oddments_list # 全部的入库数量 all_amount = decimal.Decimal(self.label_piamount.text()) # 本批零头数量 if self.lineEdit_oddment.text() not in ('', '0'): oddment_amount = decimal.Decimal(self.lineEdit_oddment.text()) return_detail.append((1, self.ppid, oddment_amount, 0, 0)) else: oddment_amount = 0 # 合箱数量 merge_amount = decimal.Decimal(self.treeWidget_oddments.topLevelItemCount()) * self.a_box_samount # 本批整箱数量 spamount_of_total_box = all_amount - oddment_amount - merge_amount return_detail.append((0, self.ppid, spamount_of_total_box,0 ,0)) return return_detail 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
class OddmentdrawnoteModule(QWidget, Ui_Form): """ 半成品发放记录 autoid: 发放表的ppid kind: 0为登记记录,1为发放记录 """ def __init__(self, ppid, parent=None): super(OddmentdrawnoteModule, self).__init__(parent) self.ppid = ppid self.setupUi(self) self.PC = ProductController() # 获取零头发放信息 self.get_oddmentdraw() def get_oddmentdraw(self): self.treeWidget_oddmentlist.clear() self.treeWidget_oddmentlist.hideColumn(0) values_tupe = ("autoid", "registerid", "registername", "regdate", "batchno", "amount", "unit", "drawerid", "drawername", "drawdate") key_dict = {'dppid': self.ppid} res = self.PC.get_oddmentdrawnotes(False, *values_tupe, **key_dict) if len(res): for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText( 1, item['registerid'] + ' ' + item['registername']) qtreeitem.setText(2, str(item['regdate'])) qtreeitem.setText(3, str(item['amount'])) qtreeitem.setText(4, item['unit']) qtreeitem.setText(5, item['batchno']) qtreeitem.setText(6, item['drawerid'] + ' ' + item['drawername']) qtreeitem.setText(7, str(item['drawdate'])) for i in range(1, 8): self.treeWidget_oddmentlist.resizeColumnToContents(i) @pyqtSlot(QPoint) def on_treeWidget_oddmentlist_customContextMenuRequested(self, pos): sender_widget = self.sender() menu = QMenu() qtreeitem = sender_widget.currentItem() button1 = menu.addAction("增加") if qtreeitem is not None: button2 = menu.addAction("删除") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if qtreeitem is None: if action == button1: detail = SelectoddmentdrawModule(ppid=self.ppid, parent=self) detail.exec() else: autoid = int(qtreeitem.text(0)) if action == button1: detail = SelectoddmentdrawModule(ppid=self.ppid, parent=self) detail.exec() elif action == button2: detail = { 'dppid': 0, 'drawerid': '', 'drawername': '', 'drawdate': '' } self.PC.update_oddmentdrawnotes(autoid=autoid, **detail) self.get_oddmentdraw()
class SelectoddmentdrawModule(QDialog, Ui_Dialog): def __init__(self, ppid, parent=None): super(SelectoddmentdrawModule, self).__init__(parent) self.setupUi(self) self.ppid = ppid self.prodid = '' self.id_list = tuple() self.PC = ProductController() # 获取ppid对应的prodid self.get_prodid() # 查找prodid相同的记录,并保存这些记录的id_list self.get_id_list() # 零头记录中找到没有过有效期且没有被领取(dppid=0) self.get_oddments_list() def get_prodid(self): values_list = ('prodid', ) key_dict = {'autoid': self.ppid} res = self.PC.get_producingplan(True, *values_list, **key_dict) if len(res) == 1: self.prodid = res[0] def get_id_list(self): if not self.prodid: return values_list = ('autoid', ) key_dict = {'prodid': self.prodid} res = self.PC.get_producingplan(True, *values_list, **key_dict) # 去除本批ppid self.id_list = list(res) if self.ppid in self.id_list: self.id_list.remove(self.ppid) def get_oddments_list(self): self.treeWidget_oddmentdrawlist.clear() self.treeWidget_oddmentdrawlist.hideColumn(0) values_list = ('autoid', 'batchno', 'amount', 'unit', 'registerid', 'registername', 'regdate', 'invaliddate') # 没有发放,没有寄库,没有过期 key_dict = { 'ppid__in': self.id_list, 'dppid': 0, 'status': 0, 'invaliddate__gte': user.now_date, } res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict) if not len(res): return for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentdrawlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['batchno']) qtreeitem.setText(2, str(item['amount'])) qtreeitem.setText(3, item['unit']) qtreeitem.setText(4, item['registerid'] + ' ' + item['registername']) qtreeitem.setText(5, str(item['regdate'])) qtreeitem.setText(6, str(item['invaliddate'])) qtreeitem.setCheckState(1, 0) for i in range(1, 7): self.treeWidget_oddmentdrawlist.resizeColumnToContents(i) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_oddmentdrawlist_itemDoubleClicked( self, qtreeitem, p_int): state = qtreeitem.checkState(1) if state == 0: qtreeitem.setCheckState(1, 2) else: qtreeitem.setCheckState(1, 0) @pyqtSlot() def on_pushButton_accept_clicked(self): it = QTreeWidgetItemIterator(self.treeWidget_oddmentdrawlist) select_id_list = [] while it.value(): qtreeitem = it.value() if qtreeitem.checkState(1) == 2: select_id_list.append(int(qtreeitem.text(0))) it += 1 if not len(select_id_list): return detail = { 'dppid': self.ppid, 'drawerid': user.user_id, 'drawername': user.user_name, 'drawdate': user.now_date } res = self.PC.update_oddmentdrawnotes(select_id_list, **detail) if res: self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class OddmentregisternoteModule(QWidget, Ui_Form): """ 零头登记记录 autoid: 登记表的ppid flag: 零头的状态 0:已登记 1:已发放 2:已寄库 3:已入库 4:已过期 """ def __init__(self, ppid, parent=None): super(OddmentregisternoteModule, self).__init__(parent) self.ppid = ppid self.setupUi(self) self.PC = ProductController() # 获取半成品信息 self.get_oddmentreg() def get_oddmentreg(self): self.treeWidget_oddmentlist.clear() self.treeWidget_oddmentlist.hideColumn(0) values_tupe = ("autoid", "registerid", "registername", "regdate", "batchno", "amount", "unit", "invaliddate", "drawerid", "drawername", "drawdate", "qaid", "qaname", "qadate", "warehousemanid", "warehousemanname", "warehousedate", "flag") key_dict = {'ppid': self.ppid} res = self.PC.get_oddmentdrawnotes(False, *values_tupe, **key_dict) if len(res): for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['regdate'])) qtreeitem.setText(2, str(item['amount'])) qtreeitem.setText(3, item['unit']) qtreeitem.setText(4, item['batchno']) qtreeitem.setText( 5, item['registerid'] + ' ' + item['registername']) qtreeitem.setText(6, str(item['invaliddate'])) qtreeitem.setText(7, item['drawerid'] + ' ' + item['drawername']) qtreeitem.setText( 8, str(item['drawdate']) if type(item['drawdate']) is datetime.date else '') qtreeitem.setText(9, item['qaid'] + ' ' + item['qaname']) qtreeitem.setText( 10, str(item['qadate']) if type(item['qadate']) is datetime.date else '') qtreeitem.setText( 11, item['warehousemanid'] + ' ' + item['warehousemanname']) qtreeitem.setText( 12, str(item['warehousedate']) if type(item['warehousedate']) is datetime.date else '') qtreeitem.setText(13, ODDMENT_STATUS[item['flag']]) for i in range(1, 14): self.treeWidget_oddmentlist.resizeColumnToContents(i) @pyqtSlot(QPoint) def on_treeWidget_oddmentlist_customContextMenuRequested(self, pos): sender_widget = self.sender() menu = QMenu() qtreeitem = sender_widget.currentItem() button1 = menu.addAction("增加") if qtreeitem is not None: button2 = menu.addAction("修改") button3 = menu.addAction("删除") button4 = menu.addAction("提交寄库") button5 = menu.addAction("取消寄库") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if qtreeitem is None: if action == button1: detail = Modifyoddmentmodule(ppid=self.ppid, parent=self) detail.exec() else: autoid = int(qtreeitem.text(0)) if action == button1: detail = Modifyoddmentmodule(ppid=self.ppid, parent=self) detail.exec() elif action == button2: detail = Modifyoddmentmodule(autoid=autoid, ppid=self.ppid, parent=self) detail.exec() elif action == button3: self.PC.delete_oddmentdrawnotes(autoid=autoid) elif action == button4: flag = qtreeitem.text(13) if ODDMENT_STATUS.index(flag) == 0: detail = { 'flag': 2, 'qaid': user.user_id, 'qaname': user.user_name, 'qadate': user.now_date } self.PC.update_oddmentdrawnotes(autoid=autoid, **detail) elif action == button5: flag = qtreeitem.text(13) if ODDMENT_STATUS.index(flag) == 2: detail = { 'flag': 0, 'qaid': '', 'qaname': '', 'qadate': None } self.PC.update_oddmentdrawnotes(autoid=autoid, **detail) self.get_oddmentreg() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_oddmentlist_itemDoubleClicked(self, qtreeitem, p_int): autoid = int(qtreeitem.text(0)) detail = Modifyoddmentmodule(autoid=autoid, ppid=self.ppid, parent=self) detail.exec() self.get_oddmentreg()
class Modifyoddmentmodule(QDialog, Ui_Dialog): """ 修改/增加新的零头登记记录 """ def __init__(self, autoid: int = 0, ppid: int = 0, parent=None): super(Modifyoddmentmodule, self).__init__(parent) self.autoid = autoid self.ppid = ppid self.batchno = '0' self.setupUi(self) self.PC = ProductController() self.SC = SystemController() self.ori_detail = dict() self.new_detail = dict() self.proddetail = {'spunit': '', 'basicunit': ''} self.validdate = 90 # 获取生产记录里小包装单位和基本单位 self.get_producingplan_detail() # 获取当前零头登记的详情 self.get_detail() # 设置数量的校验器 self.set_amount_validator() # 获取零头有效期天数 self.get_oddmentvaliddate() def get_producingplan_detail(self): values_list = ('spunit', 'basicunit', 'makedate') key_dict = {'autoid': self.ppid} res = self.PC.get_producingplan(True, *values_list, **key_dict) if len(res) != 1: return self.proddetail = res[0] self.comboBox_unit.addItems(self.proddetail[0:2]) def get_detail(self): if not self.autoid: self.dateEdit_regdate.setDate(user.now_date) values_list = ("batchno", ) key_dict = {'autoid': self.ppid} res = self.PC.get_producingplan(False, *values_list, **key_dict) if len(res) == 1: self.batchno = res[0]['batchno'] return values_list = ("amount", "unit", "regdate") key_dict = {'autoid': self.autoid} res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict) if len(res) == 1: self.ori_detail = res[0] self.lineEdit_amount.setText(str(self.ori_detail['amount'])) self.comboBox_unit.setCurrentText(self.ori_detail['unit']) self.dateEdit_regdate.setDate( self.ori_detail['regdate'] if type(self.ori_detail['regdate']) \ is datetime.datetime else user.now_date ) def set_amount_validator(self): doublevalidator = QDoubleValidator() doublevalidator.setBottom(0) self.lineEdit_amount.setValidator(doublevalidator) def get_oddmentvaliddate(self): values_list = ('otvalue', ) key_dict = {'otid': 11} res = self.SC.get_systemoption(True, *values_list, **key_dict) if len(res): self.validdate = res[0] @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(str) def on_comboBox_unit_currentTextChanged(self, p_str): try: if p_str != self.ori_detail['unit']: self.new_detail['unit'] = p_str else: try: del self.new_detail['unit'] except KeyError: pass except KeyError: self.new_detail['unit'] = p_str @pyqtSlot(QDate) def on_dateEdit_regdate_dateChanged(self, q_date): res = self.PC.get_oddment_invaliddate(q_date.toPyDate(), self.validdate) invaliddate = res[0] try: if type(self.ori_detail['regdate']) is str: self.new_detail['regdate'] = q_date.toPyDate() self.new_detail['invaliddate'] = invaliddate return if q_date != QDate(self.ori_detail['regdate']): self.new_detail['regdate'] = q_date.toPyDate() self.new_detail['invaliddate'] = invaliddate else: try: del self.new_detail['regdate'] del self.new_detail['invaliddate'] except KeyError: pass except KeyError: self.new_detail['regdate'] = q_date.toPyDate() self.new_detail['invaliddate'] = invaliddate @pyqtSlot() def on_pushButton_accept_clicked(self): if self.lineEdit_amount.text() == '': return if not len(self.new_detail): return self.new_detail['registerid'] = user.user_id self.new_detail['registername'] = user.user_name if self.autoid: res = self.PC.update_oddmentdrawnotes(autoid=self.autoid, **self.new_detail) else: self.new_detail['ppid'] = self.ppid self.new_detail['batchno'] = self.batchno self.new_detail['makedate'] = self.proddetail[2] res = self.PC.update_oddmentdrawnotes(**self.new_detail) if res: self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class OddmentputinnoteModule(QWidget, Ui_Form): """ 零头登记/发放列表记录记录 分6个标签,0:全部批记录,包括没有零头记录的批次; 1:登记中; 2:已发放; 3:已寄库 4:已入库 5:已过期 点击其中一条生产记录时下方显示对应的记录内容 除了已过期标签下的零头记录外,其他的都没有功能,只允许查看 """ def __init__(self, parent=None): super(OddmentputinnoteModule, self).__init__(parent) self.setupUi(self) if '34' not in user.powers: self.close() if user.powers['34'] == 0: self.close() self.power = '{:03b}'.format(user.powers['34']) self.ppid = 0 self.PC = ProductController() self.ori_detail = dict() self.new_detail = dict() self.groupBox.setVisible(False) # 获取当前状态的批生产记录 self.get_proddetail() def get_proddetail(self): self.treeWidget_prodlist.clear() self.treeWidget_prodlist.hideColumn(0) values_tuple_prod = ("autoid", "prodid", "prodname", "commonname", "spec", "package", "planamount", "basicunit") index = self.tabWidget.currentIndex() key_dict_prod = dict() key_dict_oddment = {'flag': index + 2} values_list_oddment = ['ppid'] id_list = self.PC.get_oddmentdrawnotes(True, *values_list_oddment, **key_dict_oddment) if not len(id_list): return key_dict_prod['autoid__in'] = id_list.distinct() res = self.PC.get_producingplan(False, *values_tuple_prod, **key_dict_prod) for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_prodlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['prodid'] + ' ' + item['prodname']) qtreeitem.setText(2, item['commonname']) qtreeitem.setText(3, item['spec']) qtreeitem.setText(4, item['package']) qtreeitem.setText(5, str(item['planamount']) + item['basicunit']) for i in range(1, 6): self.treeWidget_prodlist.resizeColumnToContents(i) # 获取零头信息 def get_oddmentdetail(self): self.treeWidget_oddmentlist.clear() self.treeWidget_oddmentlist.hideColumn(0) values_list = ("autoid", "amount", "unit", "registerid", "registername", "regdate", "invaliddate", "qaid", "qaname", "qadate", "warehousemanid", "warehousemanname", "warehousedate") key_dict = {'ppid': self.ppid} index = self.tabWidget.currentIndex() key_dict['flag'] = index + 2 res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict) if len(res): for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentlist) qtreeitem.setText(0, str(item['autoid'])) # autoid qtreeitem.setText(1, str(item['amount'])) # 数量 qtreeitem.setText(2, item['unit']) # 单位 qtreeitem.setText(3, item['registerid'] + ' ' + item['registername']) # 登记人 qtreeitem.setText(4, str(item['regdate'])) # 登记日期 qtreeitem.setText(5, str(item['invaliddate'])) # 过期日期 qtreeitem.setText(6, item['qaid'] + ' ' + item['qaname']) # 寄库人 qtreeitem.setText( 7, str(item['qadate']) if type(item['qadate']) is datetime.date else '') # 寄库日期 qtreeitem.setText(8, item['warehousemanid'] + ' ' + item['warehousemanname']) # 入库人 qtreeitem.setText(9, str(item['warehousedate']) if type(item['warehousedate']) is datetime.date else '') # 入库日期 for i in range(1, 10): self.treeWidget_oddmentlist.resizeColumnToContents(i) @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): getattr(self, 'tab_' + str(p_int)).setLayout(self.gridLayout_2) self.get_proddetail() self.groupBox.setVisible(False) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_prodlist_itemClicked(self, qtreeitem, p_int): if not self.groupBox.isVisible(): self.groupBox.setVisible(True) self.ppid = int(qtreeitem.text(0)) self.get_oddmentdetail() @pyqtSlot(QPoint) def on_treeWidget_oddmentlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return index = self.tabWidget.currentIndex() if index != 0: return # 返回调用者的对象 sender_widget = self.sender() select_items = sender_widget.selectedItems() if not len(select_items): return id_list = [] for item in select_items: id_list.append(int(item.text(0))) menu = QMenu() button1 = menu.addAction("确认寄库") button2 = menu.addAction("取消寄库") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = { 'flag': 3, 'warehousemanid': user.user_id, 'warehousemanname': user.user_name, 'warehousedate': user.now_date } self.PC.update_oddmentdrawnotes(id_list, **detail) self.get_proddetail() self.get_oddmentdetail() elif action == button2: detail = {'flag': 0, 'qaid': '', 'qaname': '', 'qadate': None} self.PC.update_oddmentdrawnotes(id_list, **detail) self.get_proddetail() self.get_oddmentdetail()