예제 #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 EditSaleOrderMudule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, parent=None):
        super(EditSaleOrderMudule, 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'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid=autoid
        self.SC = SaleController()
        self.ori_detail = dict()
        self.new_detail = dict()
        row = ('autoid', 'clientid', 'clientname', 'address')
        key = ('clientid', 'clientname', 'inputcode')
        row_name = ("id", "客户编号", "客户名称", "客户地址")
        self.lineEdit_client.setup('Client', row, key, row_name, None, 550, 290)
        if self.autoid is None:
            self.set_paperno()
            self.dateEdit_saledate.setDate(user.now_date)
            self.dateEdit_deliverydate.setDate(user.now_date)
        else:
            self.get_detail()
        self.set_conveyance_list()
        self.set_paymethod_list()

    def get_detail(self):
        key_dict = {'autoid': self.autoid}
        detail_list = self.SC.get_salenotes(
            False, *VALUES_TUPLE_ORDER, **key_dict
        )
        if not len(detail_list):
            return
        self.ori_detail = detail_list[0]
        self.lineEdit_paperno.setText(self.ori_detail['paperno'])
        self.lineEdit_client.setText(
            self.ori_detail['clientid'] + ' ' + self.ori_detail['clientname']
        )
        self.lineEdit_deliveryplace.setText(self.ori_detail['deliveryplace'])
        self.lineEdit_linkman.setText(self.ori_detail['linkman'])
        self.lineEdit_telno.setText(self.ori_detail['telno'])
        self.dateEdit_saledate.setDate(self.ori_detail['saledate'])
        self.dateEdit_deliverydate.setDate(self.ori_detail['deliverydate'])
        self.lineEdit_remark.setText(self.ori_detail['remark'])

    def set_paperno(self):
        res = self.SC.get_salenotes(True, *VALUES_TUPLE_PAPERNO)
        if not len(res):
            return ''
        max_paperno = res.order_by('-paperno')[0]
        num = re.findall('\d+', max_paperno)[-1]
        new_num = str(int(num) + 1)
        i = len(new_num)
        while i < len(num):
            new_num = '0' + new_num
            i += 1

        max_paperno = max_paperno.replace(num, new_num)
        self.lineEdit_paperno.setText(max_paperno)

    def set_conveyance_list(self):
        items = self.SC.get_salenotes(True, *VALUES_TUPLE_CONVEYANCE)\
            .distinct()
        if len(items):
            self.comboBox_conveyance.addItems(items)
        if len(self.ori_detail):
            self.comboBox_conveyance.setCurrentText(
                self.ori_detail['conveyance']
            )
        else:
            self.comboBox_conveyance.setCurrentText('')

    def set_paymethod_list(self):
        items = self.SC.get_salenotes(True, *VALUES_TUPLE_PAYMETHOD)\
            .distinct()
        if len(items):
            self.comboBox_paymethod.addItems(items)
        if len(self.ori_detail):
            self.comboBox_paymethod.setCurrentText(
                self.ori_detail['paymethod']
            )
        else:
            self.comboBox_paymethod.setCurrentText('')

    @pyqtSlot(str)
    def on_lineEdit_client_textChanged(self, p_str):
        if len(p_str.split(' ')) != 2 and p_str != '':
            return
        id, name = p_str.split(' ') if p_str != '' else ('', '')
        key_dict = {'clientid': id, 'clientname': name}
        res = self.SC.get_client(False, *VALUES_TUPLE_CLIENT, **key_dict)

        if len(res):
            client_detail = res[0]
            self.lineEdit_deliveryplace.setText(client_detail['address'])
            self.lineEdit_linkman.setText(client_detail['linkman'])
            self.lineEdit_telno.setText(client_detail['telno'])
            # self.new_detail['deliveryplace'] = client_detail['address']
            # self.new_detail['linkman'] = client_detail['linkman']
            # self.new_detail['telno'] = client_detail['telno']
            self.new_detail['salerid'] = client_detail['salerid']
            self.new_detail['salername'] = client_detail['salername']
        try:
            if id != self.ori_detail['clientid'] or name != self.ori_detail[
                'clientname']:
                self.new_detail['clientid'] = id
                self.new_detail['clientname'] = name
            else:
                try:
                    del self.new_detail['clientid']
                    del self.new_detail['clientname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['clientid'] = id
            self.new_detail['clientname'] = name

    @pyqtSlot(QDate)
    def on_dateEdit_saledate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['saledate']) is str:
                self.new_detail['saledate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['saledate']):
                self.new_detail['saledate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['saledate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['saledate'] = q_date.toPyDate()

    @pyqtSlot(QDate)
    def on_dateEdit_deliverydate_dateChanged(self, q_date):
        try:
            if type(self.ori_detail['deliverydate']) is str:
                self.new_detail['deliverydate'] = q_date.toPyDate()
                return
            if q_date != QDate(self.ori_detail['bpdate']):
                self.new_detail['deliverydate'] = q_date.toPyDate()
            else:
                try:
                    del self.new_detail['bpdate']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['deliverydate'] = q_date.toPyDate()

    @pyqtSlot(str)
    def on_lineEdit_paperno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['paperno']:
                self.new_detail['paperno'] = p_str
            else:
                try:
                    del self.new_detail['paperno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['paperno'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_deliveryplace_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['deliveryplace']:
                self.new_detail['deliveryplace'] = p_str
            else:
                try:
                    del self.new_detail['deliveryplace']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['deliveryplace'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_linkman_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['linkman']:
                self.new_detail['linkman'] = p_str
            else:
                try:
                    del self.new_detail['linkman']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['linkman'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_telno_textChanged(self, p_str):
        try:
            if p_str != self.ori_detail['telno']:
                self.new_detail['telno'] = p_str
            else:
                try:
                    del self.new_detail['telno']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['telno'] = p_str

    @pyqtSlot(str)
    def on_comboBox_conveyance_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['conveyance']:
                self.new_detail['conveyance'] = p_str
            else:
                try:
                    del self.new_detail['conveyance']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['conveyance'] = p_str

    @pyqtSlot(str)
    def on_comboBox_paymethod_currentTextChanged(self, p_str):
        try:
            if p_str != self.ori_detail['paymethod']:
                self.new_detail['paymethod'] = p_str
            else:
                try:
                    del self.new_detail['paymethod']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['paymethod'] = p_str

    @pyqtSlot(str)
    def on_lineEdit_remark_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_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        if 'paperno' in self.new_detail:
            key_dict = {'paperno': self.new_detail['paperno']}
            res = self.SC.get_salenotes(True, *VALUES_TUPLE_PAPERNO, **key_dict)
            if len(res):
                msg = MessageBox(
                    self, text="单号重复,请修改后重新提交",
                    informative="已经存在单号为" + self.new_detail['paperno'] +
                                "的记录了!"
                )
                msg.show()
                self.lineEdit_paperno.setFocus()
                return
        self.new_detail['creatorid'] = user.user_id
        self.new_detail['creatorname'] = user.user_name
        self.SC.update_salenotes(self.autoid, **self.new_detail)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()