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 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")
Beispiel #3
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()