Пример #1
0
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")
Пример #2
0
class SaleOrderListModule(QWidget, Ui_Form):
    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 get_order_list(self):
        self.treeWidget_orderlist.clear()
        self.treeWidget_orderlist.hideColumn(0)
        index = self.tabWidget.currentIndex()
        key_dict = {'status': index}
        order_list = self.SC.get_salenotes(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['clientid'] + ' ' + item['clientname'])
            qtreeitem.setText(3, item['linkman'])
            qtreeitem.setText(4, item['telno'])
            qtreeitem.setText(5, str(item['saledate']))
            qtreeitem.setText(6, str(item['deliverydate']))
            qtreeitem.setText(7, item['deliveryplace'])
            qtreeitem.setText(8, item['salerid'] + ' ' + item['salername'])
            qtreeitem.setText(9, item['conveyance'])
            qtreeitem.setText(10, item['paymethod'])
            qtreeitem.setText(
                11, item['consignmentid'] + ' ' + item['consignmentname'])
            qtreeitem.setText(12,
                              item['deliverid'] + ' ' + item['delivername'])
            qtreeitem.setText(13, item['remark'])
        for i in range(1, 14):
            self.treeWidget_orderlist.resizeColumnToContents(i)

    def get_product_list(self):

        self.treeWidget_prodlist.clear()
        self.treeWidget_prodlist.hideColumn(0)
        key_dict = {'snid': self.snid}
        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)

    @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.snid = int(qtreeitem.text(0))
        self.get_product_list()

    @pyqtSlot(QPoint)
    def on_treeWidget_orderlist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        id = 0
        index = self.tabWidget.currentIndex()
        # 返回调用者的对象
        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("取消提交")
        elif index == 2:
            button7 = menu.addAction("取消发货")
        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if index == 0:
            if action == button1:
                detail = EditSaleOrderMudule(parent=self)
                detail.accepted.connect(self.get_order_list)
                detail.show()
            elif action == button2:
                if id is None:
                    return
                detail = EditSaleOrderMudule(id, self)
                detail.accepted.connect(self.get_order_list)
                detail.show()
            elif action == button3:
                if id is None:
                    return

                key_dict_output = {'snid': id}
                res = self.WC.get_productputoutpaper(True,
                                                     *VALUES_TUPLE_OUTPUT,
                                                     **key_dict_output)
                if len(res):
                    key_dict_qrcode = {'ppopid': res[0]}
                    qrcodelist = self.WC.get_ppopqrcode(
                        True, *VALUES_TUPLE_OUTPUTDATE, **key_dict_qrcode)
                    if len(qrcodelist):
                        msg = MessageBox(self, text="已有出库记录,无法取消发货!")
                        msg.show()
                key_dict = {'snid': id}
                self.SC.delete_salenotes(id)
                self.SC.delete_salenotegoods(**key_dict)
                self.WC.delete_productputoutpaper(**key_dict)
                self.get_order_list()
            elif action == button4:
                if id is None:
                    return
                key_dict = {'status': 1}
                self.SC.update_salenotes(id, **key_dict)
                self.get_order_list()
        elif index == 1:
            if action == button5:
                if id is None:
                    return
                key_dict = {
                    'consignmentid': user.user_id,
                    'consignmentname': user.user_name,
                    'status': 2
                }
                self.SC.update_salenotes(id, **key_dict)
                key_dict_output = {'snid': id}
                res = self.WC.get_productputoutpaper(False,
                                                     *VALUES_TUPLE_OUTPUT,
                                                     **key_dict_output)
                if not len(res):
                    output_detail = {
                        'snid': id,
                        'snpaperno': current_item.text(1),
                        'pokind': "销售出库",
                        'clientid': current_item.text(2).split(' ')[0],
                        'clientname': current_item.text(2).split(' ')[1],
                        'remark': current_item.text(13)
                    }
                    res = self.WC.update_productputoutpaper(**output_detail)
                self.get_order_list()
            elif action == button6:
                if id is None:
                    return
                key_dict = {
                    'consignmentid': '',
                    'consignmentname': '',
                    'status': 0
                }
                self.SC.update_salenotes(id, **key_dict)
                self.get_order_list()
        elif index == 2:
            if action == button7:
                if id is None:
                    return
                key_dict = {
                    'consignmentid': '',
                    'consignmentname': '',
                    'status': 1
                }
                self.SC.update_salenotes(id, **key_dict)
                self.get_order_list()

    @pyqtSlot(QPoint)
    def on_treeWidget_prodlist_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 = EditSaleProdMudule(snid=self.snid, parent=self)
            detail.accepted.connect(self.get_product_list)
            detail.show()

        elif action == button2:
            if not id:
                return
            detail = EditSaleProdMudule(autoid=id, parent=self)
            detail.accepted.connect(self.get_product_list)
            detail.show()
        elif action == button3:
            if not id:
                return
            key_dict_prod = {'autoid': id}
            lab_list = self.SC.delete_salenotegoods(**key_dict_prod)
            self.get_product_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 = EditSaleOrderMudule(autoid=id, parent=self)
        detail.accepted.connect(self.get_order_list)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_prodlist_itemDoubleClicked(self, qtreeitem, p_int):
        index = self.tabWidget.currentIndex()
        if index != 0:
            return
        id = int(qtreeitem.text(0))
        detail = EditSaleProdMudule(autoid=id, parent=self)
        detail.accepted.connect(self.get_product_list)
        detail.show()