class EditpurstuffModule(QDialog, Ui_Dialog): def __init__(self, spid, ppid=None, autoid=None, parent=None): super(EditpurstuffModule, self).__init__(parent) self.ori_detail = dict() self.new_detail = dict() self.SC = SupplyerController() self.SFC = StuffController() self.setupUi(self) # row = ('autoid', 'stuffid', 'stuffname', 'spec', 'package') # key = ('stuffid', 'stuffname', 'stuffkind', 'inputcode') # row_name = ('id', '物料编号', '物料名称', '含量规格', '包装规格') # self.lineEdit_supplyer.setup('Supplyer', row, key, row_name, 539, 240) self.autoid = autoid self.spid = spid self.ppid = ppid self.get_detail() self.set_amount_validator() def get_detail(self): if not self.autoid: return key_dict = {'autoid': self.autoid} res = self.SC.get_purchstuff(False, *VALUES_TUPLE_PPLIST, **key_dict) if len(res) != 1: return self.ori_detail = res[0] self.lineEdit_stuff.setText(self.ori_detail['stuffid'] + ' ' + self.ori_detail['stuffname']) self.label_spec.setText(self.ori_detail['spec']) self.label_package.setText(self.ori_detail['package']) self.lineEdit_amount.setText(str(self.ori_detail['amount'])) self.label_unit.setText(self.ori_detail['unit']) def set_amount_validator(self): doubleValitor = QDoubleValidator() doubleValitor.setBottom(0) doubleValitor.setDecimals(3) doubleValitor.setNotation(QDoubleValidator.StandardNotation) self.lineEdit_amount.setValidator(doubleValitor) @pyqtSlot(str) def on_lineEdit_amount_textChanged(self, p_str): try: if p_str != self.ori_detail['amount']: self.new_detail['amount'] = p_str else: try: del self.new_detail['amount'] except KeyError: pass except KeyError: self.new_detail['amount'] = p_str @pyqtSlot() def on_toolButton_more_clicked(self): detail = SelectstuffModule(self.spid, self) detail.selected.connect(self.set_stuff) detail.show() def set_stuff(self, p_int): key_dict = {'autoid': p_int} res = self.SFC.get_stuffdict(False, *VALUES_TUPLE_STUFF, **key_dict) if not len(res): return stuff = res[0] self.lineEdit_stuff.setText(stuff['stuffid'] + stuff['stuffname']) self.label_spec.setText(stuff['spec']) self.label_package.setText(stuff['package']) self.label_unit.setText(stuff['spunit']) self.new_detail['stuffid'] = stuff['stuffid'] self.new_detail['stuffname'] = stuff['stuffname'] self.new_detail['spec'] = stuff['spec'] self.new_detail['package'] = stuff['package'] self.new_detail['unit'] = stuff['spunit'] self.new_detail['stufftype'] = stuff['stufftype'] self.new_detail['expireddays'] = stuff['expireddays'] self.lineEdit_amount.setFocus() @pyqtSlot() def on_pushButton_accept_clicked(self): text = '' if self.lineEdit_stuff.text() == '': text = "物料不能为空!\n" if self.lineEdit_amount.text() in ('', '0'): text += "采购数量不能为空!\n" if len(text) > 0: message = MessageBox(self, text="以下信息填写错误", informative=text) message.show() return if len(self.new_detail): if self.ppid: self.new_detail['ppid'] = self.ppid res = self.SC.update_purchstuff(self.autoid, **self.new_detail) self.accept() @pyqtSlot() def on_pushButton_cancel_clicked(self): self.close()
class PurchasingplanModule(QWidget, Ui_Form): """ 采购计划表记录 分3个标签,0:编辑状态;允许随意修改 1:正在执行;只运行提交完成/退回编辑 2:已完成;只能查看不能修改 """ def __init__(self, parent=None): super(PurchasingplanModule, self).__init__(parent) self.setupUi(self) if '6' not in user.powers: self.close() if user.powers['6'] == 0: self.close() self.power = '{:03b}'.format(user.powers['6']) self.SC = SupplyerController() self.ppid = None self.ori_detail = dict() self.new_detail = dict() self.groupBox.setVisible(False) # 获取当前状态的采购记录 self.get_orderdetail() def get_orderdetail(self): self.treeWidget_orderlist.clear() self.treeWidget_orderlist.hideColumn(0) self.treeWidget_orderlist.hideColumn(1) index = self.tabWidget.currentIndex() key_dict_prod = { 'status': index } res = self.SC.get_purchasingplan( False, *VALUES_TUPLE_ORDER, **key_dict_prod ) for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_orderlist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, str(item['spid'])) qtreeitem.setText(2, item['paperno']) qtreeitem.setText(3, item['supid'] + ' ' + item['supname']) qtreeitem.setText(4, str(item['createdate'])) qtreeitem.setText(5, item['creatorid'] + ' ' + item['creatorname']) qtreeitem.setText( 6, item['warrantorid'] + ' ' + item['warrantorname'] ) qtreeitem.setText(7, str(item['invaliddate'])) qtreeitem.setText(8, item['remark']) for i in range(2, 9): self.treeWidget_orderlist.resizeColumnToContents(i) # 获取物料信息 def get_stuffdetail(self): self.treeWidget_stufflist.clear() self.treeWidget_stufflist.hideColumn(0) key_dict = { 'ppid': self.ppid } res = self.SC.get_purchstuff( False, *VALUES_TUPLE_STUFF, **key_dict ) if len(res): for item in res: qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist) qtreeitem.setText(0, str(item['autoid'])) qtreeitem.setText(1, item['stuffid'] + ' ' + item['stuffname']) qtreeitem.setText(2, STUFF_TYPE[item['stufftype']]) qtreeitem.setText(3, item['spec']) qtreeitem.setText(4, item['package']) qtreeitem.setText(5, str(item['amount'])) qtreeitem.setText(6, str(item['arrivedamount'])) qtreeitem.setText(7, item['unit']) qtreeitem.setText(8, item['producer']) for i in range(1, 9): self.treeWidget_stufflist.resizeColumnToContents(i) @pyqtSlot(int) def on_tabWidget_currentChanged(self, p_int): getattr(self, 'tab_' + str(p_int)).setLayout(self.gridLayout_2) self.get_orderdetail() self.groupBox.setVisible(False) @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_orderlist_itemClicked(self, qtreeitem, p_int): if not self.groupBox.isVisible(): self.groupBox.setVisible(True) self.ppid = int(qtreeitem.text(0)) self.get_stuffdetail() @pyqtSlot(QTreeWidgetItem, int) def on_treeWidget_orderlist_itemDoubleClicked(self, qtreeitem, p_int): index = self.tabWidget.currentIndex() if index != 0: return id = int(qtreeitem.text(0)) detail = EditpurchasingplanModule(id, self) detail.accepted.connect(self.get_orderdetail) detail.show() @pyqtSlot(QPoint) def on_treeWidget_orderlist_customContextMenuRequested(self, pos): if self.power[1] == '0': return id = 0 index = self.tabWidget.currentIndex() if index == 2: return # 返回调用者的对象 sender_widget = self.sender() current_item = sender_widget.currentItem() if current_item is not None: id = int(current_item.text(0)) menu = QMenu() if index == 0: button1 = menu.addAction("新增计划单") button2 = menu.addAction("修改计划单") button3 = menu.addAction("删除计划单") button4 = menu.addAction("提交执行") elif index == 1: button5 = menu.addAction("完成计划单") button6 = menu.addAction("退回编辑") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if index == 0: if action == button1: detail = EditpurchasingplanModule(None, self) detail.accepted.connect(self.get_orderdetail) detail.show() elif action == button2: detail = EditpurchasingplanModule(id, self) detail.accepted.connect(self.get_orderdetail) detail.show() elif action == button3: if id is None: return key_dict = { 'ppid': id } self.SC.delete_purchstuff(**key_dict) self.SC.delete_purchasingplan(id) elif action == button4: if id is None: return warrantor = current_item.text(5) if warrantor in ('', ' '): message = MessageBox( self, text="无法提交执行", informative="批准人还没有签名" ) message.show() return key_dict = { 'status': 1 } self.SC.update_purchasingplan(id, **key_dict) elif index == 1: if action == button5: if id is None: return key_dict = { 'status': 2 } self.SC.update_purchasingplan(id, **key_dict) elif action == button6: if id is None: return key_dict = { 'status': 0 } self.SC.update_purchasingplan(id, **key_dict) self.get_orderdetail() @pyqtSlot(QPoint) def on_treeWidget_stufflist_customContextMenuRequested(self, pos): if self.power[1] == '0': return id = [] index = self.tabWidget.currentIndex() if index != 0: return order_item = self.treeWidget_orderlist.currentItem() if order_item is None: return ppid = order_item.text(0) spid = order_item.text(1) # 返回调用者的对象 sender_widget = self.sender() select_items = sender_widget.selectedItems() if select_items is not None: for item in select_items: id.append(int(item.text(0))) menu = QMenu() button1 = menu.addAction("新增物料") button2 = menu.addAction("修改物料") button3 = menu.addAction("删除物料") global_pos = sender_widget.mapToGlobal(pos) action = menu.exec(global_pos) if action == button1: detail = EditpurstuffModule(spid, ppid, None, self) detail.accepted.connect(self.get_stuffdetail) detail.show() elif action == button2: current_item = sender_widget.currentItem() current_id = int(current_item.text(0)) detail = EditpurchasingplanModule(spid, None, current_id, self) detail.accepted.connect(self.get_stuffdetail) detail.show() elif action == button3: if id is None: return key_dict = { 'autoid__in': id } self.SC.delete_purchstuff(**key_dict) self.get_stuffdetail()
class WarehouseController(object): def __init__(self): self.SC = StuffController() self.SLC = SaleController() self.SP = SupplyerController() self.WM = WarehouseModel() self.WC = WorkshopController() self.PC = ProductController() def get_stuffdrawpaper(self, *args, **kwargs): return self.SC.get_stuffdrawpaper(*args, **kwargs) """if len(res): ppid_list = list() for item in res: ppid_list.append(item.ppid) value_tuple = ( 'autoid', 'prodid', 'prodname', 'spec', 'package', 'batchno') prod_info_tuple = self.WM.get_producingplan(*value_tuple, autoid__in=set( ppid_list)) for item in res: for it in prod_info_tuple: if item.ppid == it[0]: item.prod = it[1] + ' ' + it[2] item.spec = it[3] item.package = it[4] item.batchno = it[5] return res else: return []""" def get_stuffrepository(self, display_flag=False, *args, **kwargs): return self.WM.get_stuffrepository(display_flag, *args, **kwargs) """res = self.WM.get_stuffrepository(flag, *args, **kwargs) supid_list = [] if len(res): for item in res: supid_list.append(item['supid']) supplyers = self.SP.get_supply(('supid', 'supname'), supid__in=set(supid_list)) for item in res: item['supname'] = '' for supplyer in supplyers: if item['supid'] == supplyer[0]: item['supname'] = supplyer[1] break return res """ def update_stuffrepository(self, autoid=None, *args, **kwargs): return WarehouseModel.update_stuffrepository(autoid, *args, **kwargs) def update_stuffrepository_amount(self, ppid, *args, **kwargs): return WarehouseModel.update_stuffrepository_amount( ppid, *args, **kwargs) def get_productputoutpaper(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_productputoutpaper(display_flag, *args, **kwargs) def update_productputoutpaper(self, autoid=None, *args, **kwargs): return WarehouseModel.update_productputoutpaper( autoid, *args, **kwargs) def delete_productputoutpaper(self, autoid=None, *args, **kwargs): return WarehouseModel.delete_productputoutpaper( autoid, *args, **kwargs) def get_prodwithdrawnote(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_prodwithdrawnote(display_flag, *args, **kwargs) def update_prodwithdrawnote(self, autoid, *args, **kwargs): return WarehouseModel.update_prodwithdrawnote(autoid, *args, **kwargs) def delete_prodwithdrawnote(self, autoid, *args, **kwargs): return WarehouseModel.delete_prodwithdrawnote(autoid, *args, **kwargs) def get_ppopqrcode(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_ppopqrcode(display_flag, *args, **kwargs) def update_ppopqrcode(self, autoid, *args, **kwargs): return WarehouseModel.update_ppopqrcode(autoid, *args, **kwargs) def delete_ppopqrcode(self, autoid, *args, **kwargs): return WarehouseModel.delete_ppopqrcode(autoid, *args, **kwargs) def get_pwqrcode(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_pwqrcode(display_flag, *args, **kwargs) def update_pwqrcode(self, autoid, *args, **kwargs): return WarehouseModel.update_pwqrcode(autoid, *args, **kwargs) def delete_pwqrcode(self, autoid, *args, **kwargs): return WarehouseModel.delete_pwqrcode(autoid, *args, **kwargs) def get_stuffcheckin(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_stuffcheckin(display_flag, *args, **kwargs) def update_stuffcheckin(self, autoid, *args, **kwargs): return WarehouseModel.update_stuffcheckin(autoid, *args, **kwargs) def new_stuffcheckin(self, ppid, *args, **kwargs): detail = dict() key_dict = {'ppid': ppid} stuff_query = self.SP.get_purchstuff(False, *VALUES_TUPLE_PPLIST, **key_dict) if not len(stuff_query): return stuff_list = list(stuff_query) with transaction.atomic(): p1 = transaction.savepoint() res = WarehouseModel.update_stuffcheckin(None, *args, **kwargs) for item in stuff_list: if item['amount'] - item['arrivedamount'] <= 0: continue detail['paperno'] = res.paperno detail['papertype'] = 0 detail['makedate'] = user.now_date detail['expireddate'] = user.now_date + datetime.timedelta( days=item['expireddays']) detail['checkindate'] = user.now_date detail['amount'] = item['amount'] - item['arrivedamount'] detail['piamount'] = item['amount'] - item['arrivedamount'] detail['supid'] = kwargs['supid'] detail['supname'] = kwargs['supname'] del item['amount'] del item['arrivedamount'] del item['expireddays'] detail.update(item) WarehouseModel.update_stuffcheckinlist(None, **detail) def delete_stuffcheckin(self, autoid, *args, **kwargs): return WarehouseModel.delete_stuffcheckin(autoid, *args, **kwargs) def get_stuffcheckinlist(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_stuffcheckinlist(display_flag, *args, **kwargs) def update_stuffcheckinlist(self, autoid, *args, **kwargs): return WarehouseModel.update_stuffcheckinlist(autoid, *args, **kwargs) def delete_stuffcheckinlist(self, autoid, *args, **kwargs): return WarehouseModel.delete_stuffcheckinlist(autoid, *args, **kwargs) def get_productrepository(self, display_flag=False, *args, **kwargs): return WarehouseModel.get_productrepository(display_flag, *args, **kwargs) def update_productrepository(self, autoid, *args, **kwargs): return WarehouseModel.update_productrepository(autoid, *args, **kwargs) def delete_productrepository(self, autoid, *args, **kwargs): return WarehouseModel.delete_productrepository(autoid, *args, **kwargs) def find_prodqrcode(self, qrcode): """ 产品二维码中是否找到输入的二维码(qrcode) 返回4个参数 第一个参数 0: 找到二维码且(全部)未使用 1: 找到二维码但(全部)已被使用 2: 找到二维码但(部分)已被使用 3: 找不到二维码 第二个参数 二维码级别 第三个参数 二维码对应的数量 第四个参数 二维码所在的ppid,选择结果集中的第一个ppid 第五个二维码 二维码所在的batchno,选择结果集的第一个batchno """ key_dict_0 = {'qrcode0': qrcode} key_dict_1 = {'qrcode1': qrcode} key_dict_2 = {'qrcode2': qrcode} key_dict_3 = {'qrcode3': qrcode} res = None i = 0 for i in range(0, 4): res = self.WC.get_prodqrcode(False, *VALUES_TUPLE_PRODQRCODE, **locals()['key_dict_' + str(i)]) if len(res): break if not len(res): return 3, i, 0, 0, '' res_dist = res.distinct() sum = len(res) amount = self.sum_to_amount(sum, i, res_dist[0]['ppid']) if len(res_dist) == 2: return 2, i, amount, res_dist[0]['ppid'], res_dist[0]['batchno'] elif len(res_dist) == 1: item = res_dist[0] if item['used'] == 0: return 0, i, amount, item['ppid'], item['batchno'] else: return 1, i, amount, item['ppid'], item['batchno'] else: return False def sum_to_amount(self, sum, i, ppid): """把二维码次数转位数量 :parameter sum:二维码的数量 i:第几级二维码 ppid: 对应的批生产记录 :return amount: 转换后的数量 首先要获取ppid对应记录的扫码比例 如果是0则 则amount=sum,否则amount=sum*没有扫码的级别数量 """ key_dict_pp = {'autoid': ppid} res = self.PC.get_producingplan(False, *VALUES_TUPLE_PP, **key_dict_pp) if not len(res): return 1 qrtype = res[0]['qrtype'] amount_list = (res[0]['bpamount'], res[0]['mpamount'], res[0]['spamount']) if qrtype == 1: return sum for key, value in enumerate('{:04b}'.format(qrtype)[::-1]): if value == '1': break elif value == '0': sum *= amount_list[2 - key] return sum def add_ppopqrocde(self, flag, qrcode, detail): with transaction.atomic(): p1 = transaction.savepoint() WarehouseModel.update_ppopqrcode(**detail) key_dict = {globals()['QRCODE_KIND'][flag]: qrcode} values = {'used': 1} self.WC.update_prodqrcode(key_dict, **values) def drop_ppopqrocde(self, flag, qrcode, autoid=None, **kwargs): with transaction.atomic(): p1 = transaction.savepoint() WarehouseModel.delete_ppopqrcode(autoid, **kwargs) key_dict = {globals()['QRCODE_KIND'][flag]: qrcode} values = {'used': 0} self.WC.update_prodqrcode(key_dict, **values) def apply_productputoutpaper(self, autoid, snid=None, *args, **kwargs): with transaction.atomic(): p1 = transaction.savepoint() WarehouseModel.update_productputoutpaper(autoid, *args, **kwargs) if snid is not None: key_dict_sn = { 'status': 3, 'deliverid': user.user_id, 'delivername': user.user_name } self.SLC.update_salenotes(snid, **key_dict_sn) key_dict = {'ppopid': autoid} qrcode_list = WarehouseModel.get_ppopqrcode( False, *VALUES_TUPLE_PPOPRCODE, **key_dict).order_by('ppid') no_enough_list = [] # 大中小包装得数量 for item in qrcode_list: kind = item['kind'] amount = item['amount'] ppid = item['ppid'] if kind == 0: key_dict_rep = {'pisource': 0, 'ppid': ppid} rep_list = WarehouseModel.get_productrepository( **key_dict_rep) for rep_item in rep_list: if rep_item.stockamount - amount >= 0: rep_item.stockamount -= amount amount = 0 rep_item.save() break else: amount -= rep_item.stockamount rep_item.stockamount = 0 rep_item.save() if amount > 0: no_enough_list.append((0, ppid)) elif kind == 1: key_dict_rep = {'pisource': 1, 'ppid': ppid} # 优先比较零头的数量 rep_list = WarehouseModel.get_productrepository( **key_dict_rep) for rep_item in rep_list: if rep_item.stockamount - amount >= 0: rep_item.stockamount -= amount amount = 0 rep_item.save() break else: amount -= rep_item.stockamount rep_item.stockamount = 0 rep_item.save() if amount > 0: key_dict_rep = {'pisource': 2, 'hxid': ppid} # 优先比较零头的数量 rep_list = WarehouseModel.get_productrepository( **key_dict_rep) for rep_item in rep_list: # 剩余数量和合箱剩余数量都是足够 if rep_item.stockamount - amount >= 0 and \ rep_item.hxstockamount - amount >= 0: rep_item.stockamount -= amount rep_item.hxstockamount -= amount amount = 0 rep_item.save() break else: amount -= rep_item.hxstockamount rep_item.hxstockamount = 0 rep_item.save() if amount > 0: no_enough_list.append((1, ppid)) elif kind == 2: key_dict_rep = {'pisource': 2, 'ppid': ppid} rep_list = WarehouseModel.get_productrepository( **key_dict_rep) for rep_item in rep_list: # 剩余总数-合箱数量=本批的数量 if rep_item.stockamount - rep_item.hxstockamount - \ amount >= 0: rep_item.stockamount -= amount amount = 0 rep_item.save() break else: amount -= (rep_item.stockamount - \ rep_item.hxstockamount) rep_item.stockamount = rep_item.hxstockamount rep_item.save() if amount > 0: no_enough_list.append((2, ppid)) if len(no_enough_list): transaction.savepoint_rollback(p1) return "no enough", no_enough_list else: return 'OK' def stuffreturn(self, autoid=0, backamount_list=[], *args, **kwargs): key_dict = {'autoid': 0} with transaction.atomic(): p1 = transaction.savepoint() self.SC.update_stuffdrawpaper(autoid, *args, **kwargs) for item in backamount_list: id = item[0] backamount = item[1] key_dict['autoid'] = id sr_list = WarehouseModel.get_stuffrepository(False, **key_dict) if not len(sr_list): continue sr_item = sr_list[0] sr_item.amount += backamount sr_item.save() def get_data(self, table_num: int, display_flag=False, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "查询" + TABLE_SET[table_num][1] return WarehouseModel.get_data(table_str, err_msg, display_flag, *args, **kwargs) def update_data(self, table_num: int, condition={}, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "更新" + TABLE_SET[table_num][1] return WarehouseModel.update_data(table_str, err_msg, condition, *args, **kwargs) def delete_data(self, table_num: int, condition={}, *args, **kwargs): table_str = TABLE_SET[table_num][0] err_msg = "删除" + TABLE_SET[table_num][1] return WarehouseModel.delete_data(table_str, err_msg, condition, *args, **kwargs)