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 __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 __init__(self, ppid, sdpid, kind, parent=None): super(DrawstuffModule, self).__init__(parent) self.ppid = ppid self.sdpid = sdpid self.kind = kind self.setupUi(self) if '37' not in user.powers: self.close() if user.powers['37'] == 0: self.close() self.power = '{:03b}'.format(user.powers['37']) if self.power[1] == '0': self.pushButton_accept.setVisible(False) self.pushButton_cancel.setVisible(False) self.WC = WarehouseController() self.SC = StuffController() self.PC = ProductController() self.PLC = ProductLineConroller() self.detail = dict() self.stuff_list = [] # 当前正在修改的树节点 self.edittreeitem = None self.stuff_repository = [] # 公式错误信息 self.errormsg = [] self.treeWidget_stuffrepository.setDragDropMode(1) self.treeWidget_drawstuff.setDragDropMode(2)
def __init__(self, ppopid, parent=None): super(ScanPpopQrcodeMudule, self).__init__(parent) self.setupUi(self) self.ppopid = ppopid self.WC = WarehouseController() self.kind = 0 self.tts = Tts() self.tts.start() self.lineEdit_qrcode.setFocus()
def __init__(self, autoid, parent=None): super(SaleOrderModule, self).__init__(parent) self.setupUi(self) self.SC = SaleController() self.WC = WarehouseController() self.WSC = WorkshopController() self.autoid = autoid self.get_order_list() self.get_product_list()
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 __init__(self, parent=None): super(SaleOrderListModule, self).__init__(parent) self.setupUi(self) if '53' not in user.powers: self.close() if user.powers['53'] == 0: self.close() self.power = '{:03b}'.format(user.powers['53']) self.SC = SaleController() self.WC = WarehouseController() self.WSC = WorkshopController() self.groupBox.setVisible(False) self.snid = 0 self.get_order_list()
def __init__(self, autoid, parent=None): super(ModifyStuffParmeter, self).__init__(parent) self.ori_detail = dict() self.detail = {} self.new_detail = dict() self.WC = WarehouseController() self.SFC = StuffController() self.setupUi(self) self.autoid = autoid self.get_detail() self.set_validator() self.get_location_list()
def __init__(self, parent=None): super(ProductRepositoryModule, self).__init__(parent) self.setupUi(self) if '42' not in user.powers: self.close() if user.powers['42'] == 0: self.close() self.power = '{:03b}'.format(user.powers['42']) self.WC = WarehouseController() self.LC = LabrecordsController() self.PC = ProductController() self.current_button = self.radioButton_batchno self.get_product_list()
def __init__(self, autoid, parent=None): # autoid:退料单在stuffdrawpaper中的autoid super(StuffReturnInModule, self).__init__(parent) self.autoid = autoid self.ori_detail = dict() self.new_detail = dict() self.stuff_backamount_list = [] self.SC = StuffController() self.WC = WarehouseController() self.setupUi(self) self.pushButton_apply.setVisible(False) self.pushButton_cancel.setVisible(False) self.get_stuffdrawpaper() self.get_stufflist()
def __init__(self, parent=None): super(PurStuffCheckInModule, self).__init__(parent) self.setupUi(self) if '29' not in user.powers: self.close() if user.powers['29'] == 0: self.close() self.power = '{:03b}'.format(user.powers['29']) self.WC = WarehouseController() self.LC = LabrecordsController() self.SC = SupplyerController() self.SFC = StuffController() self.get_stuff_list()
def __init__(self, parent=None): super(QrcodeoutputModule, self).__init__(parent) self.setupUi(self) if '59' not in user.powers: self.close() if user.powers['59'] == 0: self.close() self.power = '{:03b}'.format(user.powers['59']) self.WC = WarehouseController() self.PC = ProductController() self.SC = SystemController() self.SLC = SaleController() self.orderlist = dict() # 获取二维码信息 self.get_order_list()
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()
class SaleOrderModule(QDialog, Ui_Dialog): def __init__(self, autoid, parent=None): super(SaleOrderModule, self).__init__(parent) self.setupUi(self) self.SC = SaleController() self.WC = WarehouseController() self.WSC = WorkshopController() self.autoid = autoid self.get_order_list() self.get_product_list() def get_order_list(self): key_dict = {'autoid': self.autoid} order_list = self.SC.get_salenotes(False, *VALUES_TUPLE_ORDER, **key_dict) if not len(order_list): return order = order_list[0] self.label_paperno.setText(order['paperno']) self.label_client.setText(order['clientid'] + ' ' + order['clientname']) self.label_linkman.setText(order['linkman']) self.label_telno.setText(order['telno']) self.label_saler.setText(order['salerid'] + ' ' + order['salername']) self.label_saledate.setText(str(order['saledate'])) self.label_deliveryplace.setText(order['deliveryplace']) self.label_deliverydate.setText(str(order['deliverydate'])) self.label_consignment.setText(order['consignmentid'] + ' ' + order['consignmentname']) self.label_remark.setText(order['remark']) def get_product_list(self): self.treeWidget_prodlist.clear() self.treeWidget_prodlist.hideColumn(0) key_dict = {'snid': self.autoid} prod_list = self.SC.get_salenotegoods(False, *VALUES_TUPLE_PROD, **key_dict) if not len(prod_list): return for item in prod_list: qtreeitem = QTreeWidgetItem(self.treeWidget_prodlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['prodid'] + ' ' + item['prodname']) qtreeitem.setText(2, item['spec']) qtreeitem.setText(3, item['package']) qtreeitem.setText(4, to_str(item['saleamount'])) qtreeitem.setText(5, item['spunit']) prodid = item['prodid'] key_dict_rep = {'prodid': prodid, 'stockamount__gt': 0} product_rep_list = self.WC.get_productrepository( False, *VALUES_TUPLE_REP, **key_dict_rep).annotate(amount=Sum('stockamount')) if len(product_rep_list): qtreeitem.setText(6, to_str(product_rep_list[0]['amount'])) else: qtreeitem.setText(6, '0') for i in range(1, 7): self.treeWidget_prodlist.resizeColumnToContents(i)
def __init__(self, parent=None): super(StuffReturnListModule, self).__init__(parent) self.setupUi(self) if '40' not in user.powers: self.close() if user.powers['40'] == 0: self.close() self.power = '{:03b}'.format(user.powers['40']) # 数据库操作类 self.WC = WarehouseController() # 显示物料列表 self.show_stuffdrawpaper_list() # 隐藏第一列的id self.stuffdrawpaperlist.hideColumn(0)
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) if '37' not in user.powers: self.close() if user.powers['37'] == 0: self.close() self.power = '{:03b}'.format(user.powers['37']) self.current_stuff_kind_button = self.pushButton_apply # 数据库操作类 self.WC = WarehouseController() self.pushButton_apply.clicked.connect(self.on_statusButton_clicked) self.pushButton_finish.clicked.connect(self.on_statusButton_clicked) # 显示物料列表 self.show_stuffdrawpaper_list()
def __init__(self, autoid=None, parent=None): super(EditProducingplan, self).__init__(parent) self.setupUi(self) # if '20' not in user.powers: # self.close() # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) # if user.powers['20'] == 0: # self.close() # self.power = '{:03b}'.format(user.powers['20']) # if self.power[1] == '0': # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) self.PC = ProductController() self.WC = WarehouseController() self.autoid = autoid self.prod_id = 0 self.ori_detail = {} self.new_detail = {} self.detail = {} self.stuff_list = [] self.stuff_repository = [] self.no_enough_stuff_list = [] self.treewidget_meterial.hideColumn(1) self.treeWidget_package.hideColumn(1) # 公式错误信息 self.errormsg = [] self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY, VALUE_NAME, None, 650, 250) self.prodname.getItem.connect(self.setproduct) self.set_validator() if autoid is not None: self.get_detail() self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial) self.set_treewidget_formula((3, 4), self.treeWidget_package) else: self.makedate.setDate(QDate.currentDate())
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()
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 StuffpickingModule(QDialog, Ui_Form): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) if '37' not in user.powers: self.close() if user.powers['37'] == 0: self.close() self.power = '{:03b}'.format(user.powers['37']) self.current_stuff_kind_button = self.pushButton_apply # 数据库操作类 self.WC = WarehouseController() self.pushButton_apply.clicked.connect(self.on_statusButton_clicked) self.pushButton_finish.clicked.connect(self.on_statusButton_clicked) # 显示物料列表 self.show_stuffdrawpaper_list() # 显示领料单列表内容 # stufftype默认为已提交的领料单 def show_stuffdrawpaper_list(self): self.stuffdrawpaperlist.clear() if self.current_stuff_kind_button.text() in STUFFTYPE: paperstatus = STUFFTYPE.index(self.current_stuff_kind_button.text()) key_dict = {'status': paperstatus} self.stuffdrawpaper = self.WC.get_stuffdrawpaper( False, **key_dict ).\ extra( select={ 'prodid': 'producingplan.prodid', 'prodname': 'producingplan.prodname', 'spec': 'producingplan.spec', 'package': 'producingplan.package', 'batchno': 'producingplan.batchno' }, tables=['producingplan'], where=['stuffdrawpaper.ppid=producingplan.autoid'] ) if len(self.stuffdrawpaper): self.countlabel.setText("共%s条记录" % len(self.stuffdrawpaper)) for item in self.stuffdrawpaper: stufflist = QTreeWidgetItem( self.stuffdrawpaperlist) stufflist.setText(0, str(item.autoid)) stufflist.setText(1, str(item.ppid)) stufflist.setText(2, PAPERTYPE[item.papertype]) stufflist.setText(3, item.chargerid + ' ' + item.chargername) stufflist.setText(4, str(item.applydate)) stufflist.setText(5, item.providerid + ' ' + item.providername) stufflist.setText(6, str(item.drawdate)) stufflist.setText(7, item.prodid + ' ' + item.prodname) stufflist.setText(8, item.spec) stufflist.setText(9, item.package) stufflist.setText(10, item.batchno) # 隐藏第一列的id self.stuffdrawpaperlist.hideColumn(0) self.stuffdrawpaperlist.hideColumn(1) for i in range(2, 9): self.stuffdrawpaperlist.resizeColumnToContents(i) if self.stuffdrawpaperlist.columnWidth(i) > 200: self.stuffdrawpaperlist.setColumnWidth(i, 200) else: self.countlabel.setText("共0条记录") # 刷新功能 @pyqtSlot() def on_pushButton_refresh_clicked(self): self.show_stuffdrawpaper_list() # 打开记录详情 @pyqtSlot() def on_recordButton_clicked(self): if self.stufflist.currentItem(): self.on_stufflist_itemDoubleClicked(self.stufflist.currentItem(), 0) # 物料列表双击功能 @pyqtSlot(QTreeWidgetItem, int) def on_stuffdrawpaperlist_itemDoubleClicked(self, QTreeWidgetItem, p_int): try: sdpid = QTreeWidgetItem.text(0) ppid = QTreeWidgetItem.text(1) kind = PAPERTYPE.index(QTreeWidgetItem.text(2)) # 物料详细列表 detail = DrawstuffModule(ppid, sdpid, kind, self) detail.accepted.connect(self.show_stuffdrawpaper_list) detail.finished.connect(self.not_find_proddetail) # 修改了物料记录,刷新列表 detail.showMaximized() except ValueError: SaveExcept(ValueError, "打开领料单时出错", (QTreeWidgetItem.text(1), QTreeWidgetItem.text(2))) def not_find_proddetail(self, p_int): if p_int == 6: msg = MessageBox(parent=self, title="错误", text="领料单异常!", informative="没有找到对应的产品信息!") msg.show() timer = QTimer(self) timer.start(1000) timer.timeout.connect(msg.close) @pyqtSlot() def on_statusButton_clicked(self): button_name = self.sender() if self.current_stuff_kind_button == button_name: pass else: self.current_stuff_kind_button.setEnabled(True) self.current_stuff_kind_button = button_name button_name.setEnabled(False) self.show_stuffdrawpaper_list()
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 StuffReturnListModule(QDialog, Ui_Form): def __init__(self, parent=None): super(StuffReturnListModule, self).__init__(parent) self.setupUi(self) if '40' not in user.powers: self.close() if user.powers['40'] == 0: self.close() self.power = '{:03b}'.format(user.powers['40']) # 数据库操作类 self.WC = WarehouseController() # 显示物料列表 self.show_stuffdrawpaper_list() # 隐藏第一列的id self.stuffdrawpaperlist.hideColumn(0) # 显示领料单列表内容 # stufftype默认为已提交的领料单 def show_stuffdrawpaper_list(self): self.stuffdrawpaperlist.clear() paperstatus = self.tabWidget.currentIndex() + 1 key_dict = {'wdstatus': paperstatus} self.stuffdrawpaper = self.WC.get_stuffdrawpaper(False, **key_dict).\ extra( select={ 'prodid': 'producingplan.prodid', 'prodname': 'producingplan.prodname', 'spec': 'producingplan.spec', 'package': 'producingplan.package', 'batchno': 'producingplan.batchno' }, tables=['producingplan'], where=['stuffdrawpaper.ppid=producingplan.autoid'] ).values(*VALUES_TUPLE) if not len(self.stuffdrawpaper): self.countlabel.setText("共0条记录") return self.countlabel.setText("共%s条记录" % len(self.stuffdrawpaper)) for item in self.stuffdrawpaper: stufflist = QTreeWidgetItem(self.stuffdrawpaperlist) stufflist.setText(0, str(item['autoid'])) stufflist.setText(1, PAPERTYPE[item['papertype']]) stufflist.setText( 2, item['wdchargerid'] + ' ' + item['wdchargername']) stufflist.setText(3, str(item['wddate'])) stufflist.setText(4, item['wddrawerid'] + ' ' + item['wddrawername']) stufflist.setText( 5, str(item['wddrawdate']) if type(item['wddrawdate']) is datetime.date else '') stufflist.setText(6, item['prodid'] + ' ' + item['prodname']) stufflist.setText(7, item['spec']) stufflist.setText(8, item['package']) stufflist.setText(9, item['batchno']) for i in range(1, 10): self.stuffdrawpaperlist.resizeColumnToContents(i) # 刷新功能 @pyqtSlot() def on_pushButton_refresh_clicked(self): self.show_stuffdrawpaper_list() # 物料列表双击功能 @pyqtSlot(QTreeWidgetItem, int) def on_stuffdrawpaperlist_itemDoubleClicked(self, qtreeitem, p_int): sdpid = int(qtreeitem.text(0)) # 物料详细列表 detail = StuffReturnInModule(sdpid, self) detail.accepted.connect(self.show_stuffdrawpaper_list) # 修改了物料记录,刷新列表 detail.show() @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): tab = getattr(self, 'tab_' + str(p_int)) tab.setLayout(self.gridLayout_2) self.show_stuffdrawpaper_list()
class ScanPpopQrcodeMudule(QDialog, Ui_Dialog): qrcodeAdded = pyqtSignal() def __init__(self, ppopid, parent=None): super(ScanPpopQrcodeMudule, self).__init__(parent) self.setupUi(self) self.ppopid = ppopid self.WC = WarehouseController() self.kind = 0 self.tts = Tts() self.tts.start() self.lineEdit_qrcode.setFocus() @pyqtSlot() def on_lineEdit_qrcode_returnPressed(self): p_str = self.lineEdit_qrcode.text() self.plainTextEdit_qrcode.appendPlainText(p_str) # 把中文的逗号替换为英文的逗号,防止后续分割字符串时出错 data = p_str.replace(',', ',') qrcode = data.split(',')[0] self.lineEdit_qrcode.clear() if len(qrcode) != 24: # 二维码长度不是24位 text = qrcode + ":二维码格式错误\n" self.plainTextEdit_errormsg.insertPlainText(text) self.tts.say("错码") return status, flag, amount, ppid, batchno = self.WC.find_prodqrcode(qrcode) if status == 0: detail = { 'ppopid': self.ppopid, 'ppid': ppid, 'batchno': batchno, 'qr0': qrcode, 'flag': flag, 'kind': self.kind, 'amount': amount } self.WC.add_ppopqrocde(flag, qrcode, detail) self.qrcodeAdded.emit() elif status == 1: # 此二维码已经被使用 text = qrcode + ":此二维码已被使用\n" self.plainTextEdit_errormsg.insertPlainText(text) self.tts.say("虫码") elif status == 2: # 此二维码已经被使用 text = qrcode + ":此二维码/部分下级码已被使用\n" self.plainTextEdit_errormsg.insertPlainText(text) self.tts.say("虫码") elif status == 3: # 此二维码已经被使用 text = qrcode + ":产品库中无此二维码\n" self.plainTextEdit_errormsg.insertPlainText(text) self.tts.say("错码") else: # 没有匹配到符合的情况,查询结果异常 text = qrcode + ":二维码异常\n" self.plainTextEdit_errormsg.insertPlainText(text) self.tts.say("错码") @pyqtSlot(bool) def on_radioButton_0_toggled(self, p_bool): if p_bool: self.kind = 0 @pyqtSlot(bool) def on_radioButton_1_toggled(self, p_bool): if p_bool: self.kind = 1 @pyqtSlot(bool) def on_radioButton_2_toggled(self, p_bool): if p_bool: self.kind = 2 @pyqtSlot() def on_pushButton_accept_clicked(self): self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class ModifyStuffParmeter(QDialog, Ui_Dialog): def __init__(self, autoid, parent=None): super(ModifyStuffParmeter, self).__init__(parent) self.ori_detail = dict() self.detail = {} self.new_detail = dict() self.WC = WarehouseController() self.SFC = StuffController() self.setupUi(self) self.autoid = autoid self.get_detail() self.set_validator() self.get_location_list() def get_detail(self): if not self.autoid: self.pushButton_accept.setEnabled(False) return key_dict = { 'autoid': self.autoid } res = self.WC.get_stuffrepository( False, *VALUES_TUPLE_STUFF, **key_dict ) if len(res) != 1: return self.ori_detail = res[0] self.lineEdit_content.setText(str(self.ori_detail['content'])) self.label_contentunit.setText(self.ori_detail['cunit']) self.lineEdit_water.setText(str(self.ori_detail['water'])) self.lineEdit_rdensity.setText(str(self.ori_detail['rdensity'])) self.lineEdit_impurity.setText(str(self.ori_detail['impurity'])) 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_stuffrepository( 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("") @pyqtSlot(str) def on_lineEdit_content_textChanged(self, p_str): if p_str != '': p_str = decimal.Decimal(p_str) else: p_str = decimal.Decimal(-1) try: if p_str != self.ori_detail['content']: self.new_detail['content'] = p_str else: try: del self.new_detail['content'] except KeyError: pass except KeyError: self.new_detail['content'] = p_str @pyqtSlot(str) def on_lineEdit_water_textChanged(self, p_str): if p_str != '': p_str = decimal.Decimal(p_str) else: p_str = decimal.Decimal(p_str) try: if p_str != self.ori_detail['water']: self.new_detail['water'] = p_str else: try: del self.new_detail['water'] except KeyError: pass except KeyError: self.new_detail['water'] = p_str @pyqtSlot(str) def on_lineEdit_rdensity_textChanged(self, p_str): if p_str != '': p_str = decimal.Decimal(p_str) else: p_str = decimal.Decimal(p_str) try: if p_str != self.ori_detail['rdensity']: self.new_detail['rdensity'] = p_str else: try: del self.new_detail['rdensity'] except KeyError: pass except KeyError: self.new_detail['rdensity'] = p_str @pyqtSlot(str) def on_lineEdit_impurity_textChanged(self, p_str): if p_str != '': p_str = decimal.Decimal(p_str) else: p_str = decimal.Decimal(p_str) try: if p_str != self.ori_detail['impurity']: self.new_detail['impurity'] = p_str else: try: del self.new_detail['impurity'] except KeyError: pass except KeyError: self.new_detail['impurity'] = 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() def on_pushButton_accept_clicked(self): if len(self.new_detail): self.WC.update_stuffrepository(self.autoid, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class ProductRepositoryModule(QWidget, Ui_Form): def __init__(self, parent=None): super(ProductRepositoryModule, self).__init__(parent) self.setupUi(self) if '42' not in user.powers: self.close() if user.powers['42'] == 0: self.close() self.power = '{:03b}'.format(user.powers['42']) self.WC = WarehouseController() self.LC = LabrecordsController() self.PC = ProductController() self.current_button = self.radioButton_batchno self.get_product_list() def get_product_list(self): if self.current_button == self.radioButton_batchno: self.treeWidget_productbatchnolist.setVisible(True) self.treeWidget_productkindlist.setVisible(False) current_tree = self.treeWidget_productbatchnolist current_tree.hideColumn(0) elif self.current_button == self.radioButton_kind: self.treeWidget_productbatchnolist.setVisible(False) self.treeWidget_productkindlist.setVisible(True) current_tree = self.treeWidget_productkindlist else: return current_tree.clear() key_dict = {'stockamount__gt': 0} product_list = self.WC.get_productrepository( False, **key_dict ) if not len(product_list): return if current_tree == self.treeWidget_productbatchnolist: self.set_batchno_tree(current_tree, product_list) for i in range(1, 15): current_tree.resizeColumnToContents(i) elif current_tree == self.treeWidget_productkindlist: self.set_kind_tree(current_tree, product_list) for i in range(0, 6): current_tree.resizeColumnToContents(i) else: return def set_batchno_tree(self, current_tree, product_list): p_list = product_list.values(*VALUES_TUPLE_BATCHNO) """ .extra( select={ 'prodid': 'prodid', 'prodname': 'prodname', 'spec': 'spec', 'commonname': 'commonname', 'batchno': 'batchno', 'package': 'package', 'spunit': 'spunit', 'makedate': 'makedate', 'expireddates': 'expireddates' }, tables=['producingplan'], where=['producingplan.autoid=ppid'] ) """ for item in p_list: qtreeitem = QTreeWidgetItem(current_tree) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, SOURCE[item['pisource']]) qtreeitem.setText(2, item['prodid'] + ' ' + item['prodname']) qtreeitem.setText(3, item['commonname']) if item['pisource'] == 2: key_dict = {'autoid': item['hxid']} hx_batchno_list = self.PC.get_producingplan( True, *VALUES_TUPLE_PRODUCINGPLAN, **key_dict ) hx_batchno = '' if len(hx_batchno_list): hx_batchno = hx_batchno_list[0] qtreeitem.setText(4, item['batchno'] + ' ' + hx_batchno) qtreeitem.setText( 7, to_str((item['piamount'] - item[ 'hxamount'])) + '+' + to_str(item['hxamount']) ) qtreeitem.setText( 8, to_str(item['stockamount'] - item[ 'hxstockamount']) + '+' + to_str(item['hxstockamount']) ) else: qtreeitem.setText(4, item['batchno']) qtreeitem.setText(7, str(item['piamount'])) qtreeitem.setText(8, str(item['stockamount'])) qtreeitem.setText(5, item['spec']) qtreeitem.setText(6, item['package']) qtreeitem.setText(9, item['spunit']) qtreeitem.setText(10, item['position']) qtreeitem.setText(11, str(item['indate'])) if type(item['makedate']) is datetime.date: qtreeitem.setText(12, str(item['makedate'])) qtreeitem.setText(13, str(item['expireddate'])) qtreeitem.setText( 14, item['warehousemanid'] + item['warehousemanname'] ) def set_kind_tree(self, current_tree, product_list): kind_list = product_list.values(*VALUES_TUPLE_KIND).annotate( stockamount=Sum('stockamount'), piamount=Sum('piamount') ) """ .extra( select={ 'prodid': 'prodid', 'prodname': 'prodname', 'spec': 'spec', 'commonname': 'commonname', 'package': 'package', 'spunit': 'spunit' }, tables=['producingplan'], where=['producingplan.autoid=ppid'] ). \ """ for item in kind_list: qtreeitem = QTreeWidgetItem(current_tree) qtreeitem.setText(0, item['prodid'] + item['prodname']) qtreeitem.setText(1, item['commonname']) qtreeitem.setText(2, item['spec']) qtreeitem.setText(3, item['package']) qtreeitem.setText(4, to_str(item['piamount'])) qtreeitem.setText(5, to_str(item['stockamount'])) qtreeitem.setText(6, item['spunit']) pyqtSlot(bool) def on_radioButton_batchno_toggled(self, p_bool): if p_bool: self.current_button = self.radioButton_batchno self.get_product_list() pyqtSlot(bool) def on_radioButton_kind_toggled(self, p_bool): if p_bool: self.current_button = self.radioButton_kind self.get_product_list() @pyqtSlot(QPoint) def on_treeWidget_productbatchnolist_customContextMenuRequested(self, pos): if self.power[1] == '0': return id = 0 batchno = '' sender_widget = self.sender() current_item = sender_widget.currentItem() if current_item is None: return id = int(current_item.text(0)) prodid, stuffname = current_item.text(2).split(' ') batchno = current_item.text(4) menu = QMenu() button1 = menu.addAction("查看检验报告") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = FindCheckReportModule(prodid, batchno, self) detail.show()
class EditProducingplan(QDialog, Ui_Dialog): created = pyqtSignal(int) def __init__(self, autoid=None, parent=None): super(EditProducingplan, self).__init__(parent) self.setupUi(self) # if '20' not in user.powers: # self.close() # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) # if user.powers['20'] == 0: # self.close() # self.power = '{:03b}'.format(user.powers['20']) # if self.power[1] == '0': # self.accept_button.setVisible(False) # self.cancel_button.setVisible(False) # self.pushButton_audit.setVisible(False) self.PC = ProductController() self.WC = WarehouseController() self.autoid = autoid self.prod_id = 0 self.ori_detail = {} self.new_detail = {} self.detail = {} self.stuff_list = [] self.stuff_repository = [] self.no_enough_stuff_list = [] self.treewidget_meterial.hideColumn(1) self.treeWidget_package.hideColumn(1) # 公式错误信息 self.errormsg = [] self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY, VALUE_NAME, None, 650, 250) self.prodname.getItem.connect(self.setproduct) self.set_validator() if autoid is not None: self.get_detail() self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial) self.set_treewidget_formula((3, 4), self.treeWidget_package) else: self.makedate.setDate(QDate.currentDate()) def set_validator(self): doubleValitor = QDoubleValidator() doubleValitor.setBottom(0) doubleValitor.setDecimals(2) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.planamount.setValidator(doubleValitor) def setproduct(self, qtreeitem: QTreeWidgetItem): self.prod_id = qtreeitem.text(0) self.commonname.setText(qtreeitem.text(3)) self.spec.setText(qtreeitem.text(4)) self.package_2.setText(qtreeitem.text(5)) if self.prod_id: # flag:产品的类型,0成品,1半成品,2退货, 3验证 flag = self.productkind.currentIndex() key_dict = {'autoid': self.prod_id} res = self.PC.get_product_or_stuff_dictionary( flag, False, **key_dict) if res: self.unit.setText(res[0].spunit) if flag in (0, 1): lineid = res[0].plid elif flag == 2: lineid = res[0].wplid elif flag == 3: lineid = res[0].vplid else: lineid = 0 if lineid: productline = ProductLineConroller() pline = productline.get_productline(lineid, flag) if pline: self.prodline.setText(pline[0].linename) self.productworkshop.setText(pline[0].deptid + ' ' + pline[0].deptname) def set_autoid(self, autoid: int): self.autoid = autoid # 查询autoid对应的记录,并关联到表格中 self.get_detail() self.new_detail.clear() def get_detail(self): res = self.PC.get_producingplan(autoid=self.autoid) if res: # 把生产指令的内容填入表格中 self.set_data(res[0]) self.ori_detail = model_to_dict(res[0]) self.detail = self.ori_detail else: errordialig = QErrorMessage(self) errordialig.setWindowTitle("错误") # 初始化编辑生产指令的内容 def set_data(self, detail): self.productkind.setCurrentIndex(detail.pltype) self.prodname.setText(detail.prodid + ' ' + detail.prodname) self.commonname.setText(detail.commonname) self.spec.setText(detail.spec) self.package_2.setText(detail.package) self.planamount.setText(str(detail.planamount)) self.unit.setText(detail.spunit) self.batchno.setText(detail.batchno) self.makedate.setDate( QDate(detail.makedate) if type(detail.makedate) is datetime.date else user.now_date) self.remarks.setText(detail.remark) lineid = detail.lineid if lineid: productline = ProductLineConroller() pline = productline.get_productline(lineid, detail.pltype) if pline: self.prodline.setText(pline[0].linename) self.productworkshop.setText(pline[0].deptid + ' ' + pline[0].deptname) self.new_detail['linename'] = pline[0].linename self.new_detail['workshopid'] = pline[0].deptid self.new_detail['workshopname'] = pline[0].deptname def set_treewidget_formula(self, stufftype=(0, 1, 2), qtree=None): prodtype = 1 if self.productkind.currentIndex() == 1 else 0 qtree.clear() condition = { 'prodid': self.prod_id, 'stufftype__in': stufftype, 'prodtype': prodtype } # 获取配方 self.formula = self.PC.get_data(6, False, *VALUES_TUPLE_PD, **condition) if not len(self.formula): return stuffkind_list = self.formula.values_list('stuffkind', flat=True) condition_sk = {'stuffkind__in': stuffkind_list, 'amount__gt': 0} self.stuff_repository = self.WC.get_data(2, False, *VALUES_TUPLE_SD, **condition_sk) for it in self.stuff_repository: condition_lock = {'srid': it['autoid']} drawamount_list = self.PC.get_data( 7, True, *VALUES_TUPLE_SL, **condition_lock).exclude(ppid=self.autoid) it['realamount'] = it['amount'] - sum(drawamount_list) for item in self.formula: parent_treeitem = QTreeWidgetItem(qtree) parent_treeitem.setText(0, item['stuffkind']) parent_treeitem.setText(2, item['formula']) stuffkind = item['stuffkind'] condition_sf = {'stuffkind': stuffkind, 'amount__gt': 0} # 获取库存 stuffrepository = self.WC.get_data(2, False, *VALUES_TUPLE_SD, **condition_sf) if not len(stuffrepository): brush = QBrush(1) brush.setColor(QColor(255, 85, 0)) for i in range(0, 13): parent_treeitem.setBackground(i, brush) # Decimal(rnd(eval(presexpression, evalenv(self)), # precision)) parent_treeitem.setText( 6, str(self.no_stuffrep_count_presamount(item)) + item['presunit']) self.no_enough_stuff_list.append(stuffkind) continue draw_status = self.draw_stuff(item) if not draw_status: self.no_enough_stuff_list.append(stuffkind) brush = QBrush(1) brush.setColor(QColor(255, 255, 127)) for i in range(1, 13): parent_treeitem.setBackground(i, brush) for it in stuffrepository: condition_lock = {'srid': it['autoid']} drawamount_list = self.PC.get_data(7, True, *VALUES_TUPLE_SL, **condition_lock) qtreeitem = QTreeWidgetItem(parent_treeitem) qtreeitem.setText(1, str(it['autoid'])) qtreeitem.setText(0, it['stuffname']) qtreeitem.setText(3, it['batchno']) qtreeitem.setText(4, str(it['amount'])) qtreeitem.setText(5, str(sum(drawamount_list))) for sr in self.stuff_list: if it['autoid'] == sr['autoid']: qtreeitem.setText( 7, str(sr['newpracamount']) + item['pracunit']) qtreeitem.setText( 8, str(sr['drawamount']) + item['drawunit']) parent_treeitem.setText( 6, str(sr['presamount']) + item['presunit']) break if stufftype == (0, 1, 2): qtreeitem.setText(9, str(it['content']) + it['cunit']) qtreeitem.setText(10, str(it['water']) + '%') qtreeitem.setText(11, str(it['rdensity'])) qtreeitem.setText(12, str(it['impurity'])) qtree.expandAll() qtree.resizeColumnToContents(0) for i in range(2, 13 if stufftype == (0, 1, 2) else 9): qtree.resizeColumnToContents(i) qtree.collapseAll() def no_stuffrep_count_presamount(self, item): stuffkind = item['stuffkind'] precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression(item['presexpression'], 1) # 计划量 try: presamount = Decimal( rnd(eval(presexpression, evalenv(self)), precision)) return presamount except SyntaxError: if stuffkind + ' 计划量' not in self.errormsg: self.errormsg.append(stuffkind + ' 计划量') return 0 # 系统根据配方自动领料 def draw_stuff(self, item): stuffkind = item['stuffkind'] precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression(item['presexpression'], 1) # 计划量 try: presamount = Decimal( rnd(eval(presexpression, evalenv(self)), precision)) except SyntaxError: if stuffkind + ' 计划量' not in self.errormsg: self.errormsg.append(stuffkind + ' 计划量') presamount = 0 # 实际量公式,去除系统变量 pracexpression = self.reckon_expression(item['pracexpression'], 1) # 领取量公式,去除系统变量 drawexpression = self.reckon_expression(item['drawexpression'], 1) # 计算领料量,返回领料情况res, 和标记:是否已经领购料 res = self.reckon_drawamount(stuffkind, presamount, precision, pracexpression, drawexpression, loss) if len(res): self.stuff_list_additem(res) return self.is_drawamount_enough(stuffkind, presamount) # 判断领取的物料是否足够 def is_drawamount_enough(self, stuffkind, presamount): new_presamount = 0 for item in self.stuff_list: if item['stuffkind'] == stuffkind: new_presamount += item['newpresamount'] return True if new_presamount >= presamount else False # 把领取的物料加到领料记录中,如果发现重复的情况则替换旧的记录 def stuff_list_additem(self, newitems): for newitem in newitems: flat = 0 for item in self.stuff_list: if newitem['autoid'] == item['autoid']: # item = newitem flat = 1 break if flat == 0: self.stuff_list.append(newitem) # 计算系统变量 def reckon_expression(self, expression, iterdepth): # iterdepth:迭代深度,超过50则抛出RuntimeError # 产品信息变量,ex: @planamount@, @spec@, @package@ if iterdepth > 50: raise RuntimeError pattern = re.findall(r'@[%?!()()::.#\w]*@', expression) for item in pattern: # 引用其他物料 if len(item[1:-1].split('.')) == 2: var_name, var_item = item[1:-1].split('.') value = Decimal('0') # 标记是否找到了对应的物料 find_stuff_flag = 0 for stuff in self.stuff_list: if stuff['stuffkind'] == var_name: find_stuff_flag = 1 if var_item == '计划量': value = stuff[VAR_ITEM[var_item]] expression = expression.replace(item, str(value)) break else: value += stuff[VAR_ITEM[var_item]] expression = expression.replace(item, str(value)) # 没有找到对应的物料则再本领料单中继续寻找 if find_stuff_flag == 0: for item in self.formula: try: if item['stuffkind'] == var_name: # stuffkind = item.text(2) precision = item['precision'] loss = item['loss'] # 处理产品信息的变量,去除系统变量 presexpression = self.reckon_expression( item['presexpression'], iterdepth + 1) # 计划量 try: presamount = Decimal( rnd( eval(presexpression, evalenv(self)), precision)) except SyntaxError: if var_name + ' 计划量' not in self.errormsg: self.errormsg.append(var_name + ' 计划量') presamount = 0 # 把计划量加到产品信息变量中 # self.detail['presamount'] = presamount # 实际量公式,去除系统变量 pracexpression = self.reckon_expression( item['pracexpression'], iterdepth + 1) # 领取量公式,去除系统变量 drawexpression = self.reckon_expression( item['drawexpression'], iterdepth + 1) # 计算领料量,返回领料情况res, 和标记:是否已经领购料 res = self.reckon_drawamount( var_name, presamount, precision, pracexpression, drawexpression, loss) if len(res): self.stuff_list_additem(res) # self.is_drawamount_enough() expression = self.reckon_expression( expression, iterdepth + 1) except RuntimeError: break # 引用生产指令的参数 else: key = item.replace('@', '') if key in self.detail: expression = expression.replace(item, str(self.detail[key])) # pattern_1 = re.findall(r'@[%?!()()::.#\w]*@', expression) return expression # 计算实际量 def reckon_pracamount(self, autoid, presamount, precision, expression): # stuffkind: 物料种类 # presamount: 计划量 # expression: 实际量的公式 stuff_detail = [] # 最终要领取的批次和实际量 # 分析公式,获取变量 pattern = re.findall(r'@\w*@', expression) # 把变量设置为对应的值 for item in self.stuff_repository: if autoid != item['autoid']: continue for key in pattern: k = key.replace('@', '') if k == 'presamount': expression = expression.replace(key, str(presamount)) elif k in item: expression = expression.replace(key, str(item[k])) elif k in self.detail: expression = expression.replace(key, str(self.detail[k])) try: pracamount = Decimal( rnd(eval(expression, evalenv(self)), precision)) except SyntaxError: if item['stuffkind'] + ' 实际量' not in self.errormsg: self.errormsg.append(item['stuffkind'] + ' 实际量') pracamount = 0 item['pracamount'] = pracamount # 计算领取量 # stuffkindorsrid: 根据flat决定类型, True是物料种类,False是srid # presamount: 计划量 # precision: 计算结果精度 # prac_expression: 实际量公式 # draw_expression: 领取公式 # loss: 损耗限度 # flat: 是否需要继续领下一批物料,默认为True即继续领下一批物料, # False则不再领取下一批物料 def reckon_drawamount(self, stuffkindorsrid, presamount, precision, prac_expression, draw_expression, loss=0, flat=True): # 要领取的物料批次 draw_list = [] # 已经领取了的量 has_drawamount = 0 # 分析公式,获取变量 pattern = re.findall(r'@\w*@', draw_expression) # 把变量设置为对应的值 for item in self.stuff_repository: item['presamount'] = presamount new_expression = draw_expression if has_drawamount != 0: presamount -= has_drawamount has_drawamount = 0 if stuffkindorsrid != (item['stuffkind'] if flat else str(item['autoid'])): continue item['loss'] = loss item['newpresamount'] = presamount item['precision'] = precision # 算出该批次对应的实际量 self.reckon_pracamount(item['autoid'], presamount, precision, prac_expression) for key in pattern: k = key.replace('@', '') if k in item: new_expression = new_expression.replace(key, str(item[k])) elif k in self.detail: new_expression = new_expression.replace( key, str(self.detail[k])) try: drawamount = Decimal( rnd(eval(new_expression, evalenv(self)), precision)) except SyntaxError: if stuffkindorsrid + ' 领取量' not in self.errormsg: self.errormsg.append(stuffkindorsrid + ' 领取量') drawamount = 0 continue if item['realamount'] >= drawamount: item['drawamount'] = drawamount item['newpracamount'] = item['pracamount'] draw_list.append(item) break else: # 转化为计划量 = 领取量 * 计划量 / 实际量 has_drawamount = Decimal( rnd(item['realamount'] * presamount / item['pracamount'], precision)) item['newpresamount'] = has_drawamount item['newpracamount'] = rnd(item['realamount'], precision) item['drawamount'] = rnd(item['realamount'], precision) draw_list.append(item) if not flat: # 指定库存记录时,默认按领够料处理 break return draw_list # 产品种类改变时 @pyqtSlot(int) def on_productkind_currentIndexChanged(self, p_int): if p_int in (0, 2, 3): self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY, VALUE_NAME, None, 650, 250) else: self.prodname.setup(DB_TABLE[1], STUFF_VALUE_TUPLE, STUFF_KEY, VALUE_NAME, None, 650, 250) # 修改计划量时触发 @pyqtSlot() def on_planamount_editingFinished(self): p_str = self.planamount.text() planamount = Decimal(p_str) if p_str != '' else 0 try: if planamount != self.ori_detail['planamount']: self.new_detail['planamount'] = planamount self.detail['planamount'] = planamount else: try: del self.new_detail['planamount'] except KeyError: pass except KeyError: self.new_detail['planamount'] = planamount self.detail['planamount'] = planamount self.stuff_list = [] self.stuff_repository = [] self.no_enough_stuff_list = [] self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial) self.set_treewidget_formula((3, 4), self.treeWidget_package) # 修改批号时触发 @pyqtSlot(str) def on_batchno_textEdited(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(QDate) def on_makedate_dateChanged(self, q_date): p_date = q_date.toPyDate() try: if p_date != self.ori_detail['makedate']: self.new_detail['makedate'] = p_date else: try: del self.new_detail['makedate'] except KeyError: pass except KeyError: self.new_detail['makedate'] = p_date # 修改备注时触发 @pyqtSlot(str) def on_remarks_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() def on_accept_button_clicked(self): if self.prodname.flat == 0: text = "没有找到对应的产品信息,请修改后重试!" informative = "选择好产品名称后请不要再修改,否则将导致系统无法找到正确的产品!" errordialig = MessageBox(self, text=text, informative=informative) errordialig.exec() self.prodname.setFocus() return if len(self.no_enough_stuff_list): text = "以下物料不足!" informative = ";\n".join(self.no_enough_stuff_list) errordialig = MessageBox(self, text=text, informative=informative, yes_text="继续下达指令") res = errordialig.exec() if res == 65536: self.prodname.setFocus() return # 有修改过数据 if self.new_detail: try: # 修改过记录,把当前的人员和日期存入修改记录中 self.new_detail['instructorid'] = user.user_id self.new_detail['instructorname'] = user.user_name self.new_detail['plandate'] = user.now_date self.new_detail['deptid'] = user.dept_id self.new_detail['deptname'] = user.dept_name self.new_detail['bpconstitutorid'] = user.user_id self.new_detail['bpconstitutorname'] = user.user_name self.new_detail['bpconsdate'] = user.now_date # autoid不为空,则为修改记录 # 否则为插入记录 if self.autoid: self.PC.update_producingplan(autoid=self.autoid, **self.new_detail) condition = {'ppid': self.autoid} self.PC.delete_data(7, condition) else: prodtype = self.productkind.currentIndex() prod_id = self.prodname.namelist.currentItem().text(0) self.new_detail['id'] = prod_id ppid = self.PC.update_producingplan(prodtype=prodtype, **self.new_detail) self.autoid = ppid self.created.emit(self.autoid) for item in self.stuff_list: detail = { 'ppid': self.autoid, 'srid': item['autoid'], 'drawamount': item['drawamount'], 'stuffkind': item['stuffkind'] } self.PC.update_data(7, **detail) self.accept() except Exception as e: SaveExcept(e, "提交生产指令时出错", **self.new_detail) else: self.close() @pyqtSlot() def on_cancel_button_clicked(self): self.close() @pyqtSlot() def on_pushButton_audit_clicked(self): if len(self.no_enough_stuff_list): text = "以下物料不足!无法执行指令!" informative = ";\n".join(self.no_enough_stuff_list) errordialig = MessageBox(self, text=text, informative=informative) errordialig.exec() return if self.autoid is None: self.new_detail['instructorid'] = user.user_id self.new_detail['instructorname'] = user.user_name self.new_detail['plandate'] = user.now_date self.new_detail['deptid'] = user.dept_id self.new_detail['deptname'] = user.dept_name self.new_detail['bpconstitutorid'] = user.user_id self.new_detail['bpconstitutorname'] = user.user_name self.new_detail['bpconsdate'] = user.now_date self.new_detail['status'] = 1 self.new_detail['statustime'] = user.now_time self.new_detail['warrantorid'] = user.user_id self.new_detail['warrantorname'] = user.user_name self.new_detail['warrantdate'] = user.now_date self.new_detail['qadate'] = user.now_date self.new_detail['bpwarrantorid'] = user.user_id self.new_detail['bpwarrantorname'] = user.user_name self.new_detail['bpwarrantdate'] = user.now_date if self.autoid is None: prodtype = self.productkind.currentIndex() prod_id = self.prodname.namelist.currentItem().text(0) self.new_detail['id'] = prod_id ppid = self.PC.update_producingplan(prodtype=prodtype, **self.new_detail) self.autoid = ppid self.created.emit(self.autoid) # self.PC.update_data(3, **self.new_detail) else: condition = {'autoid': self.autoid} self.PC.update_data(3, condition, **self.new_detail) for item in self.stuff_list: if item['drawamount'] == 0: continue detail = { 'ppid': self.autoid, 'srid': item['autoid'], 'drawamount': item['drawamount'], 'stuffkind': item['stuffkind'] } self.PC.update_data(7, **detail) self.accept()
class QrcodeoutputModule(QWidget, Ui_Form): """ 二维码出库文件模块,可以查看到所有订单的二维码记录。 提供了右键下载二维码。 """ def __init__(self, parent=None): super(QrcodeoutputModule, self).__init__(parent) self.setupUi(self) if '59' not in user.powers: self.close() if user.powers['59'] == 0: self.close() self.power = '{:03b}'.format(user.powers['59']) self.WC = WarehouseController() self.PC = ProductController() self.SC = SystemController() self.SLC = SaleController() self.orderlist = dict() # 获取二维码信息 self.get_order_list() def get_order_list(self): self.treeWidget_orderlist.clear() self.treeWidget_orderlist.hideColumn(0) key_dict = dict() index = self.tabWidget.currentIndex() if index in (0, 1): key_dict['status'] = index + 1 else: key_dict['status__gte'] = 1 self.orderlist = self.WC.get_productputoutpaper( False, *VALUES_LIST, **key_dict) if not len(self.orderlist): return for item in self.orderlist: qtreeitem = QTreeWidgetItem(self.treeWidget_orderlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['putoutdate'])) qtreeitem.setText(2, item['pokind']) qtreeitem.setText(3, item['clientid'] + ' ' + item['clientname']) qtreeitem.setText(4, item['auditorid'] + ' ' + item['auditorname']) qtreeitem.setText(5, str(item['remark'])) for i in range(1, 6): self.treeWidget_orderlist.resizeColumnToContents(i) @pyqtSlot(QPoint) def on_treeWidget_orderlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return qtreeitem = self.treeWidget_orderlist.selectedItems() if not len(qtreeitem): return select_id = int(qtreeitem[0].text(0)) menu = QMenu() button1 = menu.addAction("生成出库数据文件") # button2 = menu.addAction("导入入库二维码数据") # button3 = menu.addAction("覆盖入库二维码数据") g_pos = self.treeWidget_orderlist.mapToGlobal(pos) action = menu.exec(g_pos) if action == button1: clipboard = QApplication.clipboard() dir = clipboard.property("qrcodeoutputurl") filename = "出库数据" + str(user.now_date).replace("-", "") + ".xml" if not dir: dir = "C:\\" file_route, ext = QFileDialog.getSaveFileName( self, "请选择出库文件输出路径", dir + filename, "*.xml;;All Files(*)") if not file_route: return selected_dir = re.findall(r'^(.+/|.+\\)', file_route)[0] clipboard.setProperty("qrcodeoutputurl", selected_dir) self.makeqrcodeoutputfile(select_id, file_route) self.WC.update_productputoutpaper(select_id, status=2) self.get_order_list() @pyqtSlot(int) def on_tabWidget_currentChanged(self, index): getattr(self, 'tab_' + str(index)).setLayout(self.gridLayout_2) self.get_order_list() def makeqrcodeoutputfile(self, id, file_route): for item in self.orderlist: if item['autoid'] == id: proddetail = item break clientid = proddetail['clientid'] key_dict_client = {'clientid': clientid} clients_detail = self.SLC.get_client(False, *VALUES_LIST_CLIENT, **key_dict_client) if len(clients_detail) != 1: return client = clients_detail[0] key_dict = {'ppopid': id} res = self.WC.get_ppopqrcode(False, *VALUES_LIST_QRCODE, **key_dict) if not len(res): return # 把二维码按比例分组 q_list, ppid_list, batchno_list = self.sort_qrcode( res.order_by('batchno')) xml = QXmlStreamWriter() qfile = QFile(file_route) if qfile.open(QIODevice.WriteOnly): xml.setDevice(qfile) else: return xml.setAutoFormatting(True) xml.writeStartDocument() # 添加头文件信息 self.addxmlheader(xml, client['kind']) self.addxmlproddetail(xml, proddetail) temp_ppid = '' for i in range(0, len(ppid_list)): if temp_ppid != ppid_list[i]: if temp_ppid != '': # 把上一个Batch结束了 xml.writeEndElement() temp_ppid = ppid_list[i] xml.writeStartElement("Batch") xml.writeAttribute('batchNo', batchno_list[i]) xml.writeAttribute('operator', proddetail['auditorname']) xml.writeAttribute('oprDate', str(proddetail['putoutdate'])) xml.writeAttribute(' toUnit', client['clientname']) xml.writeAttribute('toProvince', client['province']) xml.writeAttribute('toCity', client['city']) xml.writeAttribute('toCounty', client['county']) xml.writeAttribute('toUnitcode', client['unitcode']) xml.writeStartElement("Data") xml.writeAttribute('code', q_list[i]) xml.writeEndElement() xml.writeEndElement() xml.writeEndElement() xml.writeEndDocument() def sort_qrcode(self, qrcode_list): q_list = [] ppid_list = [] batchno_list = [] try: for item in qrcode_list: q_list.append(item['qr0']) ppid_list.append(item['ppid']) batchno_list.append(item['batchno']) except KeyError: pass return q_list, ppid_list, batchno_list def addxmlheader(self, xml, toUnitType): company = "智普飞扬" mancode = "19060310" key_dict_sys = {'varname__in': ("company", "mancode")} res = self.SC.get_syssetting(False, *VALUES_LIST_SYS, **key_dict_sys) if len(res): for item in res: if item['varname'] == "company": company = item['varvalue'] elif item['varname'] == "mancode": mancode = item['varvalue'] xml.writeStartElement("DataList") xml.writeAttribute("corpName", company) xml.writeAttribute("toUnitType", str(toUnitType)) xml.writeAttribute("manCode", mancode) xml.writeAttribute("dataType", "wareHouseOut") xml.writeAttribute("version", "1.1") xml.writeAttribute("xmlns: xsi", "http://www.w3.org/2001/XMLSchema-instance") xml.writeAttribute("xsi: noNamespaceSchemaLocation", "兽药产品出库数据1.1.xsd") def addxmlproddetail(self, xml, proddetail): xml.writeStartElement("Product")
class ProductPutOutPaperListModule(QWidget, Ui_Form): def __init__(self, parent=None): super(ProductPutOutPaperListModule, self).__init__(parent) self.setupUi(self) if '35' not in user.powers: self.close() if user.powers['35'] == 0: self.close() self.power = '{:03b}'.format(user.powers['35']) self.SC = SaleController() self.WC = WarehouseController() self.WSC = WorkshopController() self.groupBox.setVisible(False) self.ppopid = 0 self.prod_list = {} self.get_order_list() def get_order_list(self): self.treeWidget_orderlist.clear() # self.treeWidget_orderlist.hideColumn(0) # self.treeWidget_orderlist.hideColumn(1) index = self.tabWidget.currentIndex() key_dict = {'status': index} order_list = self.WC.get_productputoutpaper(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, str(item['snid'])) qtreeitem.setText(2, item['snpaperno']) qtreeitem.setText(3, item['pokind']) qtreeitem.setText( 4, str(item['putoutdate']) if type(item['putoutdate']) is datetime.date else '') qtreeitem.setText(5, item['clientid'] + ' ' + item['clientname']) qtreeitem.setText(6, item['auditorid'] + ' ' + item['auditorname']) qtreeitem.setText(7, str(item['remark'])) for i in range(2, 8): self.treeWidget_orderlist.resizeColumnToContents(i) def get_qrcode_list(self): self.treeWidget_itemlist.clear() self.treeWidget_itemlist.hideColumn(0) key_dict = {'ppopid': self.ppopid} self.prod_list = self.WC.get_ppopqrcode(False, **key_dict).extra( select={ 'prodid': 'prodid', 'prodname': 'prodname', 'spec': 'spec', 'package': 'package', 'lpunit': 'lpunit', 'bpunit': 'bpunit', 'mpunit': 'mpunit', 'spunit': 'spunit' }, tables=['producingplan'], where=['ppid=producingplan.autoid']).values(*VALUES_TUPLE_PROD) if not len(self.prod_list): return for item in self.prod_list: package_unit = [ item['spunit'], item['mpunit'], item['bpunit'], item['lpunit'] ] qtreeitem = QTreeWidgetItem(self.treeWidget_itemlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, KIND[item['kind']]) qtreeitem.setText(2, item['prodid'] + ' ' + item['prodname']) qtreeitem.setText(3, item['batchno']) qtreeitem.setText(4, str(item['amount']) + item['spunit']) qtreeitem.setText(5, item['spec']) qtreeitem.setText(6, item['package']) qtreeitem.setText(7, item['qr0']) qtreeitem.setText(8, package_unit[item['flag']] + '码') for i in range(1, 9): self.treeWidget_itemlist.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.ppopid = int(qtreeitem.text(0)) self.get_qrcode_list() @pyqtSlot(QPoint) def on_treeWidget_orderlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return id = 0 snid = 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)) snid = int(current_item.text(1)) menu = QMenu() button1 = menu.addAction("新增出库单") button2 = menu.addAction("修改出库单") button3 = menu.addAction("删除出库单") menu.addSeparator() button4 = menu.addAction("提交出库") menu.addSeparator() button5 = menu.addAction("查看销售订单") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = EditProductPutOutPaperModule(parent=self) detail.accepted.connect(self.get_order_list) detail.show() elif action == button2: if id is None: return detail = EditProductPutOutPaperModule(id, self) detail.accepted.connect(self.get_order_list) detail.show() elif action == button3: if id is None: return key_dict_output = {'ppopid': id} res = self.WC.get_ppopqrcode(True, *VALUES_TUPLE_OUTPUT, **key_dict_output) if len(res): msg = MessageBox(self, text="已有出库记录,无法删除出库单!") msg.show() return key_dict = {'autoid': id} self.WC.delete_productputoutpaper(**key_dict) self.get_order_list() elif action == button4: if id is None: return key_dict = { 'status': 1, 'auditorid': user.user_id, 'auditorname': user.user_name, 'putoutdate': user.now_date } res = self.WC.apply_productputoutpaper(id, snid, **key_dict) if res == "OK": if snid != 0: key_dict_salenote = { 'status': 3, 'deliverid': user.user_id, 'delivername': user.user_name } self.SC.update_salenotes(snid, **key_dict_salenote) self.get_order_list() else: REP_KIND = ("整箱", "零头", "合箱") if not len(self.prod_list): self.ppopid = id self.get_qrcode_list() informative = '' prodname = '' batchno = '' for item in res[1]: for it in self.prod_list: if it['ppid'] == item[1]: prodname = it['prodname'] batchno = it['batchno'] kind = REP_KIND[item[0]] informative += prodname + '(' + kind + '),批号:' + batchno + '\n' msg = MessageBox(self, text="以下产品库存不足", informative=informative) msg.exec() return elif action == button5: if snid == 0: msg = MessageBox(self, text="没有找到关联的销售订单") msg.show() return detail = SaleOrderModule(snid, self) detail.show() @pyqtSlot(QPoint) def on_treeWidget_itemlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return id = 0 flag = 0 qrcode = '' 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)) flag = KIND.index(current_item.text(1)) qrcode = current_item.text(8) menu = QMenu() button1 = menu.addAction("增加") button2 = menu.addAction("删除") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = ScanPpopQrcodeMudule(self.ppopid, self) detail.qrcodeAdded.connect(self.get_qrcode_list) detail.show() elif action == button2: if not id: return self.WC.drop_ppopqrocde(flag, qrcode, id) self.get_qrcode_list() @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 = EditProductPutOutPaperModule(autoid=id, parent=self) detail.accepted.connect(self.get_order_list) detail.show()
class PurStuffCheckInModule(QWidget, Ui_Form): def __init__(self, parent=None): super(PurStuffCheckInModule, self).__init__(parent) self.setupUi(self) if '29' not in user.powers: self.close() if user.powers['29'] == 0: self.close() self.power = '{:03b}'.format(user.powers['29']) self.WC = WarehouseController() self.LC = LabrecordsController() self.SC = SupplyerController() self.SFC = StuffController() self.get_stuff_list() def get_stuff_list(self): self.treeWidget_stufflist.clear() self.treeWidget_stufflist.hideColumn(0) key_dict = {'status': 3, '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, str(item['lrid'])) qtreeitem.setText(2, STUFF_KIND[item['stufftype']]) qtreeitem.setText(3, item['stuffid'] + ' ' + item['stuffname']) qtreeitem.setText(4, item['batchno']) qtreeitem.setText(5, item['mbatchno']) qtreeitem.setText(6, item['spec']) qtreeitem.setText(7, item['package']) qtreeitem.setText(8, str(item['amount'])) qtreeitem.setText(9, item['unit']) qtreeitem.setText(10, item['supid'] + ' ' + item['supname']) qtreeitem.setText(11, item['producer']) for i in range(1, 12): self.treeWidget_stufflist.resizeColumnToContents(i) @pyqtSlot(QPoint) def on_treeWidget_stufflist_customContextMenuRequested(self, pos): id = 0 lrid = 0 # 返回调用者的对象 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)) menu = QMenu() button1 = menu.addAction("登记入库") button2 = menu.addAction("查看检验报告") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = EditStuffCheckInModule(id, lrid, self) detail.accepted.connect(self.get_stuff_list) detail.show() elif action == button2: if lrid == 0: message = MessageBox(text="没有找到对应的检验报告", parent=self) message.show() return detail = CheckreportModule(lrid, True, self) detail.show() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_stufflist_itemDoubleClicked(self, qtreeitem, p_int): if self.power[1] == '0': return id = int(qtreeitem.text(0)) lrid = int(qtreeitem.text(1)) detail = EditStuffCheckInModule(id, lrid, self) detail.accepted.connect(self.get_stuff_list) detail.show()