Exemplo n.º 1
0
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)
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()
Exemplo n.º 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()