Esempio n. 1
0
 def __init__(self, autoid, parent=None):
     super(HomePageModule, self).__init__(parent)
     self.setupUi(self)
     self.autoid=autoid
     self.current_img = object
     self.current_page = object
     self.PC = ProductController()
     self.WC = WorkshopController()
     self.IC = ImageController()
     # 自动缩放
     self.label_image.setScaledContents(True)
     self.get_detail()
     self.get_images()
     self.scrollArea.setVisible(False)
     self.groupBox.setVisible(False)
Esempio n. 2
0
    def __init__(self, parent=None):
        super(QrcodeinputModule, self).__init__(parent)
        self.setupUi(self)
        if '58' not in user.powers:
            self.close()
        if user.powers['58'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['58'])

        self.WC = WorkshopController()
        self.PC = ProductController()
        self.SC = SystemController()
        self.prodlist = dict()
        # 获取二维码信息
        self.get_product_list()
    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()
Esempio n. 4
0
    def __init__(self, parent=None):
        super(OddmentputinnoteModule, self).__init__(parent)
        self.setupUi(self)
        if '34' not in user.powers:
            self.close()
        if user.powers['34'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['34'])

        self.ppid = 0
        self.PC = ProductController()
        self.ori_detail = dict()
        self.new_detail = dict()
        self.groupBox.setVisible(False)
        # 获取当前状态的批生产记录
        self.get_proddetail()
Esempio n. 5
0
 def __init__(self, autoid=None, prodid=None, prodtype=0, parent=None):
     super(EditFormulaModule, self).__init__(parent)
     self.setupUi(self)
     self.autoid = autoid
     self.prodid = prodid
     self.prodtype = prodtype
     self.ori_detail = {}
     self.new_detail = {}
     self.PC = ProductController()
     self.set_validator()
     return_row = ("stufftype", "kind", )
     condition_key = {'kind', }
     treeheader_name = ["type", "物料种类"]
     self.lineEdit_stuffkind.setup(
         'Stuffdictionary', return_row, condition_key, treeheader_name, None,
         745, 200
     )
     self.get_detail()
    def __init__(self, autoid=None, parent=None):
        super(EditProducingplan, self).__init__(parent)
        self.setupUi(self)

        # if '20' not in user.powers:
        #     self.close()
        #     self.accept_button.setVisible(False)
        #     self.cancel_button.setVisible(False)
        #     self.pushButton_audit.setVisible(False)
        # if user.powers['20'] == 0:
        #     self.close()
        # self.power = '{:03b}'.format(user.powers['20'])
        # if self.power[1] == '0':
        #     self.accept_button.setVisible(False)
        #     self.cancel_button.setVisible(False)
        #     self.pushButton_audit.setVisible(False)

        self.PC = ProductController()
        self.WC = WarehouseController()

        self.autoid = autoid
        self.prod_id = 0
        self.ori_detail = {}
        self.new_detail = {}
        self.detail = {}
        self.stuff_list = []
        self.stuff_repository = []
        self.no_enough_stuff_list = []
        self.treewidget_meterial.hideColumn(1)
        self.treeWidget_package.hideColumn(1)
        # 公式错误信息
        self.errormsg = []

        self.prodname.setup(DB_TABLE[0], PRODUCT_VALUE_TUPLE, PRODUCT_KEY,
                            VALUE_NAME, None, 650, 250)

        self.prodname.getItem.connect(self.setproduct)
        self.set_validator()
        if autoid is not None:
            self.get_detail()
            self.set_treewidget_formula((0, 1, 2), self.treewidget_meterial)
            self.set_treewidget_formula((3, 4), self.treeWidget_package)
        else:
            self.makedate.setDate(QDate.currentDate())
class SelectRecordsModule(QDialog, Ui_Dialog):
    selected = pyqtSignal(int, list)

    def __init__(self, kind, parent=None):
        super(SelectRecordsModule, self).__init__(parent)
        self.kind = kind
        self.detail = []
        self.PC = ProductController()
        self.LC = LabrecordsController()
        self.setupUi(self)
        self.treeWidget_filelist.hideColumn(1)
        # 或取记录
        self.get_generalrecords()

    def get_generalrecords(self):
        if self.kind == 0:
            res = self.PC.get_data(3, False, *VALUES_TUPLE_PP)
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_filelist)
                qtreeitem.setText(0, str(item['autoid']))
                qtreeitem.setText(1, item['prodid'])
                qtreeitem.setText(2, item['prodname'])
                qtreeitem.setText(3, item['batchno'])
                qtreeitem.setText(4, item['spec'])
                qtreeitem.setText(5, item['package'])
        else:
            res = self.LC.get_data(0, False, *VALUES_TUPLE_LR)
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_filelist)
                qtreeitem.setText(0, str(item['autoid']))
                qtreeitem.setText(1, item['chkid'])
                qtreeitem.setText(2, item['chkname'])
                qtreeitem.setText(3, item['batchno'])
                qtreeitem.setText(4, item['spec'])
                qtreeitem.setText(5, item['package'])
        for i in range(1, 6):
            self.treeWidget_filelist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_filelist_itemDoubleClicked(self, qitem, p_int):
        self.selected.emit(self.kind, [int(qitem.text(0)),])
        self.accept()

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        items = self.treeWidget_filelist.selectedItems()
        select_list = []
        for item in items:
            select_list.append(int(item.text(0)))
        if len(select_list):
            self.selected.emit(self.kind, select_list)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
Esempio n. 8
0
    def __init__(self, autoid, kind, parent=None):
        super(MidproddrawnoteModule, self).__init__(parent)
        self.autoid = autoid
        self.kind = kind
        self.setupUi(self)
        self.PC = ProductController()
        self.ori_detail = dict()
        self.new_detail = dict()

        if kind == 0:
            self.treeWidget_midproductlist.headerItem().setText(3, "中间站登记人")
            self.treeWidget_midproductlist.headerItem().setText(5, "登记工人")
        elif kind == 1:
            self.treeWidget_midproductlist.headerItem().setText(3, "中间站发放人")
            self.treeWidget_midproductlist.headerItem().setText(5, "领料工人")
        # 获取半成品信息
        self.get_midprod()
        # 获取半成品的登记/发放状态
        self.get_midstatus()
 def __init__(self, autoid: int = 0, ppid: int = 0, parent=None):
     super(Modifyoddmentmodule, self).__init__(parent)
     self.autoid = autoid
     self.ppid = ppid
     self.batchno = '0'
     self.setupUi(self)
     self.PC = ProductController()
     self.SC = SystemController()
     self.ori_detail = dict()
     self.new_detail = dict()
     self.proddetail = {'spunit': '', 'basicunit': ''}
     self.validdate = 90
     # 获取生产记录里小包装单位和基本单位
     self.get_producingplan_detail()
     # 获取当前零头登记的详情
     self.get_detail()
     # 设置数量的校验器
     self.set_amount_validator()
     # 获取零头有效期天数
     self.get_oddmentvaliddate()
    def __init__(self, autoid: int = 0, ppid: int = 0, parent=None):
        super(PreProdPutInModule, self).__init__(parent)
        self.setupUi(self)
        self.ppid = ppid
        self.autoid = autoid
        self.content = decimal.Decimal('-1')
        self.water = decimal.Decimal('-1')
        self.rdensity = decimal.Decimal('-1')
        self.impurity = decimal.Decimal('-1')
        self.lrid = 0
        self.checkdate = user.now_date
        # self.units = set()
        self.unit = ''
        self.cunit = '%'
        self.expireddays = 730
        self.countercheckdays = 365
        self.WC = WorkshopController()
        self.LC = LabrecordsController()
        self.PC = ProductController()
        self.SC = StuffController()
        self.product_detail = dict()
        self.ori_detail = dict()
        self.new_detail = dict()

        # 把autoid和ppid补全
        self.get_autoid_or_ppid()
        # 获取入库位置的下拉选项
        self.get_postiton()

        # 整箱数量的校验器
        self.set_valitor(self.lineEdit_amount, 0)
        # 获取产品信息
        self.get_productdetail()
        # 设置含量单位、复检日期、有效期等参数
        self.basicdetail()

        # 获取报告书的状态和编号
        self.get_labdetail()
        # 获取入库信息
        self.get_putinnote()
    def __init__(self, autoid, parent=None):
        super(EditSampleRecordDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '50' not in user.powers:
            self.close()
        if user.powers['10'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['10'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.checkitem_id = None
        self.ori_detail = object
        self.new_detail = {}
        self.lr_list = []
        self.LC = LabrecordsController()
        self.PC = ProductController()

        self.get_detail()
        self.get_observation_record()
        self.get_labrecord_list()
Esempio n. 12
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     # 数据库操作类
     self.sd = ProductModel()
     self.product = ProductController()
     self.detail = ''
     if '2' not in  user.powers:
         self.close()
     if user.powers['2'] == 0:
         self.close()
     self.power = '{:03b}'.format(user.powers['2'])
     # 当前的物料种类,默认为“全部按键”
     #self.current_stuff_kind_button = self.ALLButton
     #self.ALLButton.clicked.connect(self.on_stufftypeButton_clicked)
     # 显示物料列表
     self.show_product_list()
     # 添加右键菜单功能
     self.__add_menu()
     # 获得所有的剂型
     medkind_list = self.product.get_all_medkind()
     self.set_medkind_list(medkind_list)
 def __init__(self, autoid:int=0, ppid: int=0, parent=None):
     super(ProductputinModule, self).__init__(parent)
     self.setupUi(self)
     self.ppid = ppid
     self.autoid = autoid
     self.bpamount = decimal.Decimal('0')
     self.mpamount = decimal.Decimal('0')
     self.spamount = decimal.Decimal('0')
     self.a_box_samount = decimal.Decimal('0')
     self.oddments_list = []
     self.units = set()
     self.WC = WorkshopController()
     self.LC = LabrecordsController()
     self.PC = ProductController()
     self.product_detail = dict()
     self.ori_detail = dict()
     self.new_detail = dict()
     if not self.ppid and not self.autoid:
         return
     # 把autoid和ppid补全
     self.get_autoid_or_ppid()
     # 获取产品信息
     self.get_productdetail()
     # 设置比例、一箱数量等参数
     self.basicdetail()
     # 获取寄库和入库位置的下拉选项
     self.get_postiton()
     # 获取报告书的状态和编号
     self.get_labdetail()
     # 获取入库信息
     self.get_putinnote()
     # 获取零头领取信息
     self.get_oddment()
     # 整箱数量的校验器
     self.set_valitor(self.lineEdit_amount, 0)
     # 零头数量的校验器
     self.set_valitor(self.lineEdit_oddment, 0, self.a_box_samount)
     self.set_total_amount()
    def __init__(self, autoid=None, parent=None):
        super(EditProductDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '2s' not in user.powers:
            self.close()
        if user.powers['2'] == 0:
            self.cloe()
        self.power = '{:03b}'.format(user.powers['2'])
        self.autoid = autoid
        self.img_status = 0
        self.images_list = []
        self.current_img = object
        self.current_page = object
        self.PC = ProductController()
        self.PLC = ProductLineConroller()
        self.LC = LabrecordsController()
        self.IC = ImageController()

        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        # 获取种类的下拉列表
        self.get_medkind_list()
        self.get_qrtype()
        self.get_workshop()
        self.get_bworkshop()
        self.get_vworkshop()
        self.get_formula()
        self.get_images()
        self.get_checkitem(3, self.treeWidget_precheckitem)
        self.get_checkitem(4, self.treeWidget_prodcheckitem)
        self.get_checkitem(6, self.treeWidget_samplecheckitem)
        self.treeWidget_formula.hideColumn(0)
        self.treeWidget_precheckitem.hideColumn(0)
        self.treeWidget_prodcheckitem.hideColumn(0)
        self.treeWidget_samplecheckitem.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(0)
        self.treeWidget_imagenamelist.hideColumn(1)
    def __init__(self, autoid=None, parent=None):
        super(EditStuffDetailModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid = autoid

        self.SC = StuffController()
        self.LC = LabrecordsController()
        self.PC = ProductController()
        self.SPC = SupplyerController()
        self.ori_detail = {}
        self.new_detail = {}
        self.get_detail()
        if len(self.ori_detail):
            stufftype = self.ori_detail['stufftype']
            if stufftype == 1:
                self.tab.removeTab(4)
                self.tab.removeTab(1)
            else:
                self.tab.removeTab(3)
                self.tab.removeTab(2)
        self.get_formula()
        self.get_checkitem(0, self.treeWidget_checkitem)
        self.get_checkitem(2, self.treeWidget_precheckitem)
        self.get_stuffsupplyer()
Esempio n. 16
0
 def __init__(self, autoid, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     self.product = ProductController()
     self.autoid = autoid
     # 当前的文档内容
     self.current_docid = 0
     self.current_content = object
     self.wsmodels = WorkshopModels()
     self.detail = self.product.get_producingplan(autoid=autoid)
     if len(self.detail) != 1:
         raise ValueError
     self.linepost = self.wsmodels.get_linepost(autoid)
     linepost_list = []
     if len(self.linepost):
         for item in self.linepost:
             linepost_list.append(item.autoid)
     self.linepostdocuments = self.wsmodels.get_linepostdocuments(
         linepost_list)
     #if len(self.linepostdocuments):
     # 初始化标题和基本信息
     self.setup_title(self.detail[0])
     # 初始化文档目录
     self.setup_filetree(list(self.linepost), list(self.linepostdocuments))
Esempio n. 17
0
    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()
Esempio n. 18
0
class ProductDetail(ProductDetailModule):
    def __init__(self, autoid=None, parent=None):
        super().__init__(parent)

        self.autoid = autoid
        self.PC = ProductController()
        self.flush_basedata()

    def flush_basedata(self):
        condition = {'autoid': self.autoid}
        res = self.PC.get_data(1, False, **condition)
        if not len(res):
            return
        self.set_data(res[0])
        self.oridetail = model_to_dict(res[0])

    def set_data(self, detail):
        self.prodid.setText(detail.prodid)
        self.prodname.setText(detail.prodname)
        self.commonname.setText(detail.commonname)
        self.medkind.setCurrentText(detail.medkind)
        self.externalno.setText(detail.externalno)
        self.allowno.setText(detail.allowno)
        self.inputcode.setText(detail.inputcode)
        self.spec.setText(detail.spec)
        self.packageLv.setCurrentIndex(int(detail.packagelv))
        self.package_2.setText(detail.package)
        self.checkunit.setCurrentIndex(detail.checkunit)
        self.expireddates.setText(str(detail.expireddates))
        self.storage.setText(detail.storage)

        if detail.plid:
            productline = ProductLineConroller()
            productlinedetail = productline.get_productline(autoid=detail.plid)
            if productlinedetail:
                self.workshop.setText(productlinedetail[0].deptname)
                self.productionline.setText(productlinedetail[0].linename)

        if detail.wplid:
            productline = ProductLineConroller()
            productlinedetail = productline.get_productline(
                autoid=detail.wplid)
            if productlinedetail:
                self.bworkshop.setText(productlinedetail[0].deptname)
                self.bproductionline.setText(productlinedetail[0].linename)
Esempio n. 19
0
class OddmentdrawnoteModule(QWidget, Ui_Form):
    """ 半成品发放记录
    autoid: 发放表的ppid
    kind: 0为登记记录,1为发放记录
    """
    def __init__(self, ppid, parent=None):
        super(OddmentdrawnoteModule, self).__init__(parent)
        self.ppid = ppid
        self.setupUi(self)
        self.PC = ProductController()
        # 获取零头发放信息
        self.get_oddmentdraw()

    def get_oddmentdraw(self):
        self.treeWidget_oddmentlist.clear()
        self.treeWidget_oddmentlist.hideColumn(0)
        values_tupe = ("autoid", "registerid", "registername", "regdate",
                       "batchno", "amount", "unit", "drawerid", "drawername",
                       "drawdate")
        key_dict = {'dppid': self.ppid}
        res = self.PC.get_oddmentdrawnotes(False, *values_tupe, **key_dict)
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentlist)
                qtreeitem.setText(0, str(item['autoid']))
                qtreeitem.setText(
                    1, item['registerid'] + ' ' + item['registername'])
                qtreeitem.setText(2, str(item['regdate']))
                qtreeitem.setText(3, str(item['amount']))
                qtreeitem.setText(4, item['unit'])
                qtreeitem.setText(5, item['batchno'])
                qtreeitem.setText(6,
                                  item['drawerid'] + ' ' + item['drawername'])
                qtreeitem.setText(7, str(item['drawdate']))

            for i in range(1, 8):
                self.treeWidget_oddmentlist.resizeColumnToContents(i)

    @pyqtSlot(QPoint)
    def on_treeWidget_oddmentlist_customContextMenuRequested(self, pos):
        sender_widget = self.sender()
        menu = QMenu()
        qtreeitem = sender_widget.currentItem()

        button1 = menu.addAction("增加")
        if qtreeitem is not None:
            button2 = menu.addAction("删除")

        global_pos = sender_widget.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if qtreeitem is None:
            if action == button1:
                detail = SelectoddmentdrawModule(ppid=self.ppid, parent=self)
                detail.exec()
        else:
            autoid = int(qtreeitem.text(0))
            if action == button1:
                detail = SelectoddmentdrawModule(ppid=self.ppid, parent=self)
                detail.exec()
            elif action == button2:
                detail = {
                    'dppid': 0,
                    'drawerid': '',
                    'drawername': '',
                    'drawdate': ''
                }
                self.PC.update_oddmentdrawnotes(autoid=autoid, **detail)

        self.get_oddmentdraw()
Esempio n. 20
0
class QrcodeinputModule(QWidget, Ui_Form):
    """ 二维码入库文件模块,可以查看到所有产品批次的二维码记录。
    提供了右键下载二维码和导入二维码的功能。

    导入二维码和覆盖二维码功能尚未实现。
    导入二维码只把文件里的数据导入,不会覆盖旧有的数据
    覆盖二维码会先把旧的二维码删除了,同时需要把二维码库中的使用状态used改未0
    导入和覆盖进行的同时还需要把新二维码在二维码库中的状态改为used=1
    """
    def __init__(self, parent=None):
        super(QrcodeinputModule, self).__init__(parent)
        self.setupUi(self)
        if '58' not in user.powers:
            self.close()
        if user.powers['58'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['58'])

        self.WC = WorkshopController()
        self.PC = ProductController()
        self.SC = SystemController()
        self.prodlist = dict()
        # 获取二维码信息
        self.get_product_list()

    def get_product_list(self):
        self.treeWidget_prodlist.clear()
        self.treeWidget_prodlist.hideColumn(0)
        key_dict = {'pltype': 0}
        index = self.tabWidget.currentIndex()
        if index in (0, 1):
            key_dict['qrflag'] = index

        self.prodlist = self.PC.get_producingplan(False, *VALUES_LIST,
                                                  **key_dict)
        if not len(self.prodlist):
            return
        for item in self.prodlist:
            qtreeitem = QTreeWidgetItem(self.treeWidget_prodlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['prodid'] + item['prodname'])
            qtreeitem.setText(2, item['batchno'])
            qtreeitem.setText(3, item['spec'])
            qtreeitem.setText(4, item['package'])
            qtreeitem.setText(5, str(item['makedate']))
        for i in range(1, 6):
            self.treeWidget_prodlist.resizeColumnToContents(i)

    @pyqtSlot(QPoint)
    def on_treeWidget_prodlist_customContextMenuRequested(self, pos):
        if self.power[1] == '0':
            return
        qtreeitem = self.treeWidget_prodlist.selectedItems()
        if not len(qtreeitem):
            return
        select_ppid = int(qtreeitem[0].text(0))

        menu = QMenu()
        button1 = menu.addAction("生成入库数据文件")
        # button2 = menu.addAction("导入入库二维码数据")
        # button3 = menu.addAction("覆盖入库二维码数据")
        g_pos = self.treeWidget_prodlist.mapToGlobal(pos)
        action = menu.exec(g_pos)
        if action == button1:
            clipboard = QApplication.clipboard()
            dir = clipboard.property("qrcodeinputurl")
            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("qrcodeinputurl", selected_dir)

            self.makeqrcodeinputfile(select_ppid, file_route)
            self.PC.update_producingplan(select_ppid, qrflag=1)
            self.get_product_list()

    @pyqtSlot(int)
    def on_tabWidget_currentChanged(self, index):
        getattr(self, 'tab_' + str(index)).setLayout(self.gridLayout_2)
        self.get_product_list()

    def makeqrcodeinputfile(self, ppid, file_route):
        for item in self.prodlist:
            if item['autoid'] == ppid:
                proddetail = item
                break
        key_dict = {'ppid': ppid}
        res = self.WC.get_qrcoderep(False, *VALUES_LIST_QRCODE, **key_dict)
        if not len(res):
            return
        # 把二维码按比例分组
        q_list, proportion_list = self.sort_qrcode(res)
        # 把比例相同的合并成一个同一个项目
        q_list_merge, proportion_list_merge = self.merge_qrcode(
            q_list, proportion_list)
        xml = QXmlStreamWriter()
        qfile = QFile(file_route)
        if qfile.open(QIODevice.WriteOnly):
            xml.setDevice(qfile)
        else:
            return

        xml.setAutoFormatting(True)
        xml.writeStartDocument()
        # 添加头文件信息
        self.addxmlheader(xml)
        self.addxmlproddetail(xml, proddetail)
        for i in range(0, len(proportion_list_merge)):
            spnum = proportion_list[i][0]
            mpnum = proportion_list[i][1]
            bpnum = proportion_list[i][2]
            lpnum = proportion_list[i][3]
            xml.writeStartElement("Batch")
            xml.writeAttribute('batchNo', proddetail['batchno'])
            xml.writeAttribute('specification', proddetail['spec'])
            xml.writeAttribute('minPackUnit', proddetail['spunit'])
            if spnum != 0:
                minTagUnit = proddetail['spunit']
            elif mpnum != 0:
                minTagUnit = proddetail['mpunit']
            else:
                minTagUnit = proddetail['bpunit']
            tagPackRatio = ''
            for num in (lpnum, bpnum, mpnum, spnum):
                if num != 0:
                    if tagPackRatio == '':
                        tagPackRatio = str(num)
                    else:
                        tagPackRatio += ':' + str(num)
            xml.writeAttribute('minTagUnit', minTagUnit)
            xml.writeAttribute('tagPackRatio', tagPackRatio)
            xml.writeAttribute('produceDate', str(proddetail['makedate']))
            xml.writeAttribute('operator', user.user_name)
            xml.writeAttribute('oprDate', str(user.now_date))
            xml.writeAttribute('count', str(len(q_list_merge[i])))
            xml.writeAttribute('countUnit',
                               '1' if minTagUnit == tagPackRatio else '2')
            qrcode = q_list_merge[i]
            for code in qrcode:
                xml.writeStartElement("Data")
                xml.writeAttribute('code', code)
                xml.writeEndElement()

            xml.writeEndElement()
        xml.writeEndElement()
        xml.writeEndElement()
        xml.writeEndDocument()

    def sort_qrcode(self, qrcode_list):
        q_list = []
        temp_q_list = []
        next_box = False
        # 比例
        proportion_list = []
        temp_proportion_list = []
        spnum = 0
        mpnum = 0
        bpnum = 0
        lpnum = 0

        # qrcode_s = ''
        qrcode_m = ''
        qrcode_b = ''
        qrcode_l = ''
        max_lv = 'lp'
        first_qrcode = qrcode_list[0]
        # qrcode0 = first_qrcode['qrcode0']
        # qrcode1 = first_qrcode['qrcode1']
        qrcode2 = first_qrcode['qrcode2']
        qrcode3 = first_qrcode['qrcode3']
        if qrcode3 == '' and qrcode2 == '':
            max_lv = 'mp'
        elif qrcode3 == '' and qrcode2 != '':
            max_lv = 'bp'

        for item in qrcode_list:

            if qrcode_m == '' and item['qrcode1'] != '':
                qrcode_m = item['qrcode1']
            elif qrcode_m != item['qrcode1']:
                temp_q_list.append(qrcode_m)
                qrcode_m = item['qrcode1']
                mpnum += 1
                if max_lv == 'mp':
                    next_box = True

            if qrcode_b == '' and item['qrcode2'] != '':
                qrcode_b = item['qrcode2']
            elif qrcode_b != item['qrcode2']:
                temp_q_list.append(qrcode_b)
                qrcode_b = item['qrcode2']
                bpnum += 1
                if max_lv == 'bp':
                    next_box = True
            if qrcode_l == '' and item['qrcode3'] != '':
                qrcode_l = item['qrcode3']
            elif qrcode_l != item['qrcode3']:
                temp_q_list.append(qrcode_l)
                qrcode_l = item['qrcode3']
                lpnum += 1
                if max_lv == 'lp':
                    next_box = True

            if next_box:
                q_list.append(temp_q_list)
                temp_q_list = []
                for num in (spnum, mpnum, bpnum, lpnum):
                    temp_proportion_list.append(num)
                spnum = 0
                mpnum = 0
                bpnum = 0
                lpnum = 0
                proportion_list.append(temp_proportion_list)
                temp_proportion_list = []
                next_box = False

            if item['qrcode0'] != '':
                temp_q_list.append(item['qrcode0'])
                spnum += 1
        if len(temp_q_list):
            if qrcode_m != '':
                temp_q_list.append(qrcode_m)
                mpnum += 1
            if qrcode_b != '':
                temp_q_list.append(qrcode_b)
                bpnum += 1
            if qrcode_l != '':
                temp_q_list.append(qrcode_l)
                lpnum += 1

            q_list.append(temp_q_list)
            for item in (spnum, mpnum, bpnum, lpnum):
                temp_proportion_list.append(item)
            proportion_list.append(temp_proportion_list)
        return q_list, proportion_list

    def merge_qrcode(self, q_list, proportion_list):
        q_list_merge = []
        proportion_list_merge = []
        for i in range(0, len(proportion_list)):
            proprotion = proportion_list[i]
            if proprotion in proportion_list_merge:
                index = proportion_list_merge.index(proprotion)
                q_list_merge[index] += q_list[i]
            else:
                proportion_list_merge.append(proprotion)
                q_list_merge.append(q_list[i])
        return q_list_merge, proportion_list_merge

    def addxmlheader(self, xml):
        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("manCode", mancode)
        xml.writeAttribute("dataType", "wareHouseIn")
        xml.writeAttribute("version", "1.0")
        xml.writeAttribute("xmlns: xsi",
                           "http://www.w3.org/2001/XMLSchema-instance")
        xml.writeAttribute("xsi: noNamespaceSchemaLocation",
                           "兽药产品入库数据_生产企业.xsd")

    def addxmlproddetail(self, xml, proddetail):
        xml.writeStartElement("Product")
        xml.writeAttribute("productName", proddetail['commonname'])
        xml.writeAttribute("pzwh", proddetail['allowno'])
        xml.writeAttribute(
            "packing",
            str(proddetail['basicamount']) + proddetail['basicunit'])
Esempio n. 21
0
class SelectoddmentdrawModule(QDialog, Ui_Dialog):
    def __init__(self, ppid, parent=None):
        super(SelectoddmentdrawModule, self).__init__(parent)
        self.setupUi(self)
        self.ppid = ppid
        self.prodid = ''
        self.id_list = tuple()
        self.PC = ProductController()
        # 获取ppid对应的prodid
        self.get_prodid()
        # 查找prodid相同的记录,并保存这些记录的id_list
        self.get_id_list()
        # 零头记录中找到没有过有效期且没有被领取(dppid=0)
        self.get_oddments_list()

    def get_prodid(self):
        values_list = ('prodid', )
        key_dict = {'autoid': self.ppid}
        res = self.PC.get_producingplan(True, *values_list, **key_dict)
        if len(res) == 1:
            self.prodid = res[0]

    def get_id_list(self):
        if not self.prodid:
            return
        values_list = ('autoid', )
        key_dict = {'prodid': self.prodid}
        res = self.PC.get_producingplan(True, *values_list, **key_dict)
        # 去除本批ppid
        self.id_list = list(res)
        if self.ppid in self.id_list:
            self.id_list.remove(self.ppid)

    def get_oddments_list(self):
        self.treeWidget_oddmentdrawlist.clear()
        self.treeWidget_oddmentdrawlist.hideColumn(0)

        values_list = ('autoid', 'batchno', 'amount', 'unit', 'registerid',
                       'registername', 'regdate', 'invaliddate')
        # 没有发放,没有寄库,没有过期
        key_dict = {
            'ppid__in': self.id_list,
            'dppid': 0,
            'status': 0,
            'invaliddate__gte': user.now_date,
        }
        res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict)
        if not len(res):
            return
        for item in res:
            qtreeitem = QTreeWidgetItem(self.treeWidget_oddmentdrawlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['batchno'])
            qtreeitem.setText(2, str(item['amount']))
            qtreeitem.setText(3, item['unit'])
            qtreeitem.setText(4,
                              item['registerid'] + ' ' + item['registername'])
            qtreeitem.setText(5, str(item['regdate']))
            qtreeitem.setText(6, str(item['invaliddate']))
            qtreeitem.setCheckState(1, 0)
        for i in range(1, 7):
            self.treeWidget_oddmentdrawlist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_oddmentdrawlist_itemDoubleClicked(
            self, qtreeitem, p_int):
        state = qtreeitem.checkState(1)
        if state == 0:
            qtreeitem.setCheckState(1, 2)
        else:
            qtreeitem.setCheckState(1, 0)

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        it = QTreeWidgetItemIterator(self.treeWidget_oddmentdrawlist)
        select_id_list = []
        while it.value():
            qtreeitem = it.value()
            if qtreeitem.checkState(1) == 2:
                select_id_list.append(int(qtreeitem.text(0)))
            it += 1
        if not len(select_id_list):
            return
        detail = {
            'dppid': self.ppid,
            'drawerid': user.user_id,
            'drawername': user.user_name,
            'drawdate': user.now_date
        }
        res = self.PC.update_oddmentdrawnotes(select_id_list, **detail)
        if res:
            self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
Esempio n. 22
0
    def __init__(self, autoid=None, parent=None):
        super().__init__(parent)

        self.autoid = autoid
        self.PC = ProductController()
        self.flush_basedata()
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()
Esempio n. 24
0
class EditFormulaModule(QDialog, Ui_Dialog):

    def __init__(self, autoid=None, prodid=None, prodtype=0, parent=None):
        super(EditFormulaModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid = autoid
        self.prodid = prodid
        self.prodtype = prodtype
        self.ori_detail = {}
        self.new_detail = {}
        self.PC = ProductController()
        self.set_validator()
        return_row = ("stufftype", "kind", )
        condition_key = {'kind', }
        treeheader_name = ["type", "物料种类"]
        self.lineEdit_stuffkind.setup(
            'Stuffdictionary', return_row, condition_key, treeheader_name, None,
            745, 200
        )
        self.get_detail()

    def get_detail(self):
        if self.autoid is None:
            return
        condition = {'autoid': self.autoid}
        res = self.PC.get_data(6, False, *VALUES_TUPLE_FL, **condition)
        if not len(res):
            return
        self.ori_detail = res[0]
        self.lineEdit_stuffkind.setText(self.ori_detail['stuffkind'])
        self.comboBox_stufftype.setCurrentIndex(self.ori_detail['stufftype'])
        self.lineEdit_formula.setText(self.ori_detail['formula'])
        self.lineEdit_presexpression.setText(self.ori_detail['presexpression'])
        self.lineEdit_pracexpression.setText(self.ori_detail['pracexpression'])
        self.lineEdit_drawexpression.setText(self.ori_detail['drawexpression'])
        self.lineEdit_presunit.setText(self.ori_detail['presunit'])
        self.lineEdit_pracunit.setText(self.ori_detail['pracunit'])
        self.lineEdit_drawunit.setText(self.ori_detail['drawunit'])
        self.lineEdit_precision.setText(str(self.ori_detail['precision']))
        self.lineEdit_loss.setText(str(self.ori_detail['loss']))

    def set_validator(self):
        intvalidator = QIntValidator()
        intvalidator.setBottom(0)
        self.lineEdit_precision.setValidator(intvalidator)
        doublevalidator = QDoubleValidator()
        doublevalidator.setRange(0, 100)
        self.lineEdit_loss.setValidator(doublevalidator)

    @pyqtSlot(object)
    def on_lineEdit_stuffkind_getItem(self, qtreeitem):
        self.comboBox_stufftype.setCurrentIndex(int(qtreeitem.text(0)))
        p_str = qtreeitem.text(1)
        try:
            if p_str != self.ori_detail['stuffkind']:
                self.new_detail['stuffkind'] = p_str
            else:
                try:
                    del self.new_detail['stuffkind']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['stuffkind'] = p_str

    @pyqtSlot(int)
    def on_comboBox_stufftype_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail['stufftype']:
                self.new_detail['stufftype'] = p_int
            else:
                try:
                    del self.new_detail['stufftype']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['stufftype'] = p_int

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

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

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

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

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

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

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

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

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

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        print(self.new_detail)
        if not len(self.new_detail):
            return
        if self.autoid is None:
            self.new_detail['prodid'] = self.prodid
            self.new_detail['prodtype'] = self.prodtype
            self.PC.update_data(6, **self.new_detail)
        else:
            condition = {'autoid': self.autoid}
            self.PC.update_data(6, condition, **self.new_detail)
        self.accept()


    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
Esempio n. 25
0
class EditSaleProdMudule(QDialog, Ui_Dialog):
    def __init__(self, autoid=None, snid=None, parent=None):
        super(EditSaleProdMudule, 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.snid = snid
        self.SC = SaleController()
        self.PC = ProductController()
        self.ori_detail = dict()
        self.new_detail = dict()
        row = ('autoid', 'prodid', 'prodname', 'spec', 'package')
        key = ('prodid', 'prodname', 'commonname', 'inputcode')
        row_name = ("id", "产品编号", "产品名称", "含量规格", "包装规格")
        self.lineEdit_product.setup('Productdictionary', row, key, row_name,
                                    None, 620, 190)
        self.set_validator()
        if self.autoid is not None:
            self.get_detail()

    def get_detail(self):
        key_dict = {'autoid': self.autoid}
        detail_list = self.SC.get_salenotegoods(False, *VALUES_TUPLE_PROD,
                                                **key_dict)
        if not len(detail_list):
            return
        self.ori_detail = detail_list[0]
        self.lineEdit_product.setText(self.ori_detail['prodid'] + ' ' +
                                      self.ori_detail['prodname'])
        self.label_spec.setText(self.ori_detail['spec'])
        self.label_package.setText(self.ori_detail['package'])
        self.lineEdit_amount.setText(to_str(self.ori_detail['saleamount']))
        self.label_unit.setText(self.ori_detail['spunit'])

    def set_validator(self):
        doubleValitor = QDoubleValidator()
        doubleValitor.setBottom(0)
        self.lineEdit_amount.setValidator(doubleValitor)

    @pyqtSlot(str)
    def on_lineEdit_product_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 = {'prodid': id, 'prodname': name}
        res = self.PC.get_product_or_stuff_dictionary(0, False,
                                                      *VALUES_TUPLE_PRODDICT,
                                                      **key_dict)
        if len(res):
            prod_detail = res[0]
            self.label_spec.setText(prod_detail['spec'])
            self.label_package.setText(prod_detail['package'])
            self.label_unit.setText(prod_detail['spunit'])
            try:
                if id != self.ori_detail['prodid'] or name != self.ori_detail[
                        'prodname']:
                    self.new_detail['prodid'] = id
                    self.new_detail['prodname'] = name
                    self.new_detail['spec'] = prod_detail['spec']
                    self.new_detail['package'] = prod_detail['package']
                    self.new_detail['spunit'] = prod_detail['spunit']
                else:
                    try:
                        del self.new_detail['prodid']
                        del self.new_detail['prodname']
                        del self.new_detail['spec']
                        del self.new_detail['package']
                        del self.new_detail['spunit']
                    except KeyError:
                        pass
            except KeyError:
                self.new_detail['prodid'] = id
                self.new_detail['prodname'] = name
                self.new_detail['spec'] = prod_detail['spec']
                self.new_detail['package'] = prod_detail['package']
                self.new_detail['spunit'] = prod_detail['spunit']

    @pyqtSlot(str)
    def on_lineEdit_amount_textChanged(self, p_str):

        try:
            p_num = decimal.Decimal(p_str)
            if p_num != self.ori_detail['saleamount']:
                self.new_detail['saleamount'] = p_num
            else:
                try:
                    del self.new_detail['saleamount']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['saleamount'] = p_num
        except decimal.InvalidOperation:
            pass

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        saleamount = self.lineEdit_amount.text()
        if saleamount in ('0', ''):
            msg = MessageBox(self, text="销售数量不能为空")
            msg.show()
            return
        if self.autoid is None and self.snid is not None:
            self.new_detail['snid'] = self.snid

        self.SC.update_salenotegoods(self.autoid, **self.new_detail)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
class PackageInstructionModule(QWidget, Ui_Form):

    def __init__(self, autoid, parent=None):
        super(PackageInstructionModule, self).__init__(parent)
        self.autoid = autoid
        self.setupUi(self)
        self.SC = StuffController()
        self.PC = ProductController()
        self.ori_detail = dict()
        self.new_detail = dict()
        # 获取物料信息
        self.get_stufflist()
        # 获取批包装指令信息
        self.get_detail()

    # 获取已经领取了的物料
    def get_stufflist(self):
        values_tupe = (
            "autoid", "lrid", "stuffid", "stuffname", "batchno", "spec",
            "package", "presamount", "content", "cunit", "water",
            "impurity", "rdensity", "presunit"
        )
        key_dict = {
            'ppid': self.autoid,
            'stufftype__in': (3, 4)
        }
        res = self.SC.get_prodstuff(False, *values_tupe, **key_dict)
        if len(res):
            for item in res:
                qtreeitem = QTreeWidgetItem(self.treeWidget_stufflist)
                qtreeitem.setText(0, str(item['autoid']))  # autoid
                qtreeitem.setText(1, str(item['lrid']))  # lrid
                qtreeitem.setText(2, item['stuffid'] + ' ' + item[
                    'stuffname'])  # 物料
                qtreeitem.setText(3, item['batchno'])  # 进厂批号
                qtreeitem.setText(4, item['spec'])  # 含量规格
                qtreeitem.setText(5, item['package'])  # 包装规格
                qtreeitem.setText(6, str(item['presamount']) + item[
                    'presunit'])  # 计划量
                qtreeitem.setText(7, str(item['content']) + item[
                    'cunit'])  # 含量/效价
                qtreeitem.setText(8, str(item['water']) + '%')  # 水分
                qtreeitem.setText(9, str(item['impurity']))  # 相对密度
                qtreeitem.setText(10, str(item['rdensity']))  # 杂质

            self.treeWidget_stufflist.hideColumn(0)
            self.treeWidget_stufflist.hideColumn(1)
            for i in range(2, 11):
                self.treeWidget_stufflist.resizeColumnToContents(i)



    def get_detail(self):
        values_list = (
            'bpconstitutorid', 'bpconstitutorname', 'bpwarrantorid', 'bpwarrantorname',
            'bpexecutorid', 'bpexecutorname', 'bpconsdate', 'bpwarrantdate',
            'bpexecutedate', 'bpdate'
        )
        key_dict = {
            'autoid': self.autoid
        }
        res = self.PC.get_producingplan(False, *values_list, **key_dict)
        if len(res) == 0:
            return

        self.ori_detail = res[0]
        self.pushButton_bpconstitutor.setText(
            self.ori_detail['bpconstitutorid'] + ' ' +
            self.ori_detail['bpconstitutorname']
        )
        self.pushButton_bpwarrantor.setText(
            self.ori_detail['bpwarrantorid'] + ' ' +
            self.ori_detail['bpwarrantorname']
        )
        self.pushButton_bpexecutor.setText(
            self.ori_detail['bpexecutorid'] + ' ' +
            self.ori_detail['bpexecutorname']
        )
        if type(self.ori_detail['bpconsdate']) is datetime.date:
            self.dateEdit_bpconsdate.setDate(self.ori_detail['bpconsdate'])
        if type(self.ori_detail['bpwarrantdate']) is datetime.date:
            self.dateEdit_bpwarrantdate.setDate(self.ori_detail['bpwarrantdate'])
        if type(self.ori_detail['bpexecutedate']) is datetime.date:
            self.dateEdit_bpexecutedate.setDate(self.ori_detail['bpexecutedate'])
        else:
            self.dateEdit_bpexecutedate.setDate(user.now_date)
        if type(self.ori_detail['bpdate']) is datetime.date:
            self.dateEdit_bpdate.setDate(self.ori_detail['bpdate'])
        else:
            self.dateEdit_bpdate.setDate(user.now_date)

    @pyqtSlot(bool, str)
    def on_pushButton_bpexecutor_signChanged(self, p_bool, p_str):
        id, name = p_str.split(' ') if p_bool else ('', '')
        try:
            if id != self.ori_detail['bpexecutorid'] or name != self.ori_detail[
                'bpexecutorname']:
                self.new_detail['bpexecutorid'] = id
                self.new_detail['bpexecutorname'] = name
            else:
                try:
                    del self.new_detail['bpexecutorid']
                    del self.new_detail['bpexecutorname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['bpexecutorid'] = id
            self.new_detail['bpexecutorname'] = name

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

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

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if len(self.new_detail):
            res = self.PC.update_producingplan(self.autoid, **self.new_detail)
class SelectProdictionListModule(QDialog, Ui_Dialog):

    def __init__(self, parent=None):
        super(SelectProdictionListModule, self).__init__(parent)
        self.setupUi(self)
        # 用于显示不用的批记录,0为没有找到留样记录的批记录,1为全部批记录
        self.type = 0
        self.PC = ProductController()
        self.LC = LabrecordsController()
        self.get_detail()

    def get_detail(self):
        self.treeWidget_productlist.clear()
        condition_pp = {'pltype': 0, 'status__gte': 2}
        pp_list = self.PC.get_data(
            3, False, *VALUES_TUPLE_PP, **condition_pp
        ).order_by('-autoid')
        if self.type == 0:
            res = self.LC.get_data(6,True, *VALUES_TUPLE_SP)
            conditon = {'autoid__in': res}
            pp_list = pp_list.exclude(**conditon)
        if not len(pp_list):
            return
        for item in pp_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_productlist)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['prodid'])
            qtreeitem.setText(2, item['prodname'])
            qtreeitem.setText(3, item['commonname'])
            qtreeitem.setText(4, item['batchno'])
            qtreeitem.setText(5, str(item['planamount']))
            qtreeitem.setText(6, item['spunit'])
            qtreeitem.setText(7, item['spec'])
            qtreeitem.setText(8, item['package'])
            qtreeitem.setText(9, str(item['makedate']))
            qtreeitem.setText(10, str(item['executedate']))
        for i in range(1, 11):
            self.treeWidget_productlist.resizeColumnToContents(i)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_productlist_itemDoubleClicked(self, qtreeitem, p_int):
        detail = {
            'ppid_id': int(qtreeitem.text(0)),
            'creatorid': user.user_id,
            'creatorname': user.user_name,
            'sampledate': user.now_date,
            'unit': qtreeitem.text(6),
            'expireddate': qtreeitem.text(10)
        }
        sample_record = self.LC.update_data(6, **detail)
        detail = EditSampleRecordDetailModule(sample_record.autoid, self.parent())
        detail.rejected.connect(self.accept)
        detail.accepted.connect(self.accept)
        detail.show()
        self.close()

    @pyqtSlot(bool)
    def on_radioButton_unmake_clicked(self, p_bool):
        if p_bool:
            self.type = 0
            self.get_detail()

    @pyqtSlot(bool)
    def on_radioButton_all_clicked(self, p_bool):
        if p_bool:
            self.type = 1
            self.get_detail()



    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        current_item = self.treeWidget_productlist.currentItem()
        if current_item is None:
            return
        detail = {
            'ppid_id': int(current_item.text(0)),
            'creatorid': user.user_id,
            'creatorname': user.user_name,
            'sampledate': user.now_date,
            'unit': current_item.text(6),
            'expireddate': current_item.text(10)
        }
        sample_record = self.LC.update_data(6, **detail)
        detail = EditSampleRecordDetailModule(sample_record.autoid,
                                              self.parent())
        detail.rejected.connect(self.accept)
        detail.accepted.connect(self.accept)
        detail.show()
        self.close()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
class ProductputinModule(QWidget, Ui_Form):
    accepted = pyqtSignal()

    def __init__(self, autoid:int=0, ppid: int=0, parent=None):
        super(ProductputinModule, self).__init__(parent)
        self.setupUi(self)
        self.ppid = ppid
        self.autoid = autoid
        self.bpamount = decimal.Decimal('0')
        self.mpamount = decimal.Decimal('0')
        self.spamount = decimal.Decimal('0')
        self.a_box_samount = decimal.Decimal('0')
        self.oddments_list = []
        self.units = set()
        self.WC = WorkshopController()
        self.LC = LabrecordsController()
        self.PC = ProductController()
        self.product_detail = dict()
        self.ori_detail = dict()
        self.new_detail = dict()
        if not self.ppid and not self.autoid:
            return
        # 把autoid和ppid补全
        self.get_autoid_or_ppid()
        # 获取产品信息
        self.get_productdetail()
        # 设置比例、一箱数量等参数
        self.basicdetail()
        # 获取寄库和入库位置的下拉选项
        self.get_postiton()
        # 获取报告书的状态和编号
        self.get_labdetail()
        # 获取入库信息
        self.get_putinnote()
        # 获取零头领取信息
        self.get_oddment()
        # 整箱数量的校验器
        self.set_valitor(self.lineEdit_amount, 0)
        # 零头数量的校验器
        self.set_valitor(self.lineEdit_oddment, 0, self.a_box_samount)
        self.set_total_amount()

    def get_autoid_or_ppid(self):
        values_list = ('autoid', 'ppid')
        if self.autoid:
            key_dict = {'autoid': self.autoid}
        else:
            key_dict = {'ppid': self.ppid}
        res = self.WC.get_productputinnote(False, *values_list, **key_dict)
        if not len(res):
            return
        self.autoid = res[0]['autoid']
        self.ppid = res[0]['ppid']

    def set_valitor(self, widget, bottom=0, top=0):
        intvalitor = QIntValidator()
        intvalitor.setBottom(bottom)
        if top != 0:
            intvalitor.setTop(top)
        widget.setValidator(intvalitor)

    def get_postiton(self):
        values_list_ws = ("warehouseid",)
        key_dict_ws = {
            'ppid': self.ppid
        }
        ws_list = self.WC.get_productputinnote(
            True, *values_list_ws, **key_dict_ws
        )
        if not len(ws_list):
            return
        warehouseid = ws_list[0]

        values_list_dppositon = ('dpposition',)
        values_list_positon = ('position',)
        key_dict_position = {
            'warehouseid': warehouseid
        }
        dppos_list = self.WC.get_productputinnote(
            True, *values_list_dppositon, **key_dict_position)
        pos_list = self.WC.get_productputinnote(
            True, *values_list_positon, **key_dict_position)
        if len(dppos_list):
            self.comboBox_dpposition.addItems(dppos_list.distinct())
        if len(pos_list):
            self.comboBox_piposition.addItems(pos_list.distinct())

    def get_productdetail(self):
        VALUES_LIST = (
            "prodid", "prodname", "spec", "package", "bpamount", "bpunit",
            "mpamount", "mpunit", "spamount", "spunit", "lpunit"
        )
        key_dict = {
            'autoid': self.ppid
        }
        res = self.PC.get_producingplan(
            False, *VALUES_LIST, **key_dict
        )
        if len(res) != 1:
            return
        self.product_detail = res[0]
        self.label_product.setText(
            self.product_detail['prodid'] + ' ' + \
            self.product_detail['prodname']
        )
        self.label_spec.setText(self.product_detail['spec'])
        self.label_package.setText(self.product_detail['package'])
        self.label_piunit.setText(self.product_detail['spunit'])
        self.label_dpunit.setText(self.product_detail['spunit'])

    def basicdetail(self):
        if self.product_detail['bpamount'] != decimal.Decimal('0'):
            self.bpamount = self.product_detail['bpamount']
        else:
            self.bpamount = decimal.Decimal('1')
        if self.product_detail['mpamount'] != decimal.Decimal('0'):
            self.mpamount = self.product_detail['mpamount']
        else:
            self.mpamount = decimal.Decimal('1')
        if self.product_detail['spamount'] != decimal.Decimal('0'):
            self.spamount = self.product_detail['spamount']
        else:
            self.spamount = decimal.Decimal('1')
        self.a_box_samount = self.bpamount * self.mpamount * self.spamount
        self.units = [
            self.product_detail['lpunit'], self.product_detail['bpunit'],
            self.product_detail['mpunit'], self.product_detail['spunit']
        ]

    def get_labdetail(self):
        values_list = ("paperno", "status")
        key_dict = {
            'labtype': 4,
            'ciid': self.ppid
        }
        res = self.LC.get_labrecord(
            False, *values_list, **key_dict
        )
        if not len(res):
            return
        # 选择最后一条符合条件的成品报告
        detail = res.order_by('-autoid')[0]
        self.label_reportpaperno.setText(detail['paperno'])
        self.label_checkstatus.setText(CHECK_STATUS[detail['status']])

    def get_putinnote(self):
        values_list = (
            "dpamount", "piamount", "packamount", "unittype",
            "pidate", "piapplyerid", "piapplyername", "piqaid", "piqaname",
            "warehousemanid", "warehousemanname", "pistatus", "position",
            "dpposition", "dpwarehousemanid", "dpwarehousemanname",
            "warehouseid", "warehousename", "oddment", "dpdate", "oddment"
        )
        key_dict = {
            'autoid': self.autoid
        }
        res = self.WC.get_productputinnote(
            False, *values_list, **key_dict
        )
        if not len(res):
            return
        # 选择第一条
        self.ori_detail = res[0]

        self.label_dpdate.setText(
            str(self.ori_detail['dpdate']) if type(self.ori_detail['dpdate'])
                                              is datetime.date else ''
        )
        self.label_pidate.setText(
            str(self.ori_detail['pidate']) if type(self.ori_detail['pidate'])
                                              is datetime.date else ''
        )
        self.comboBox_unittype.setCurrentIndex(self.ori_detail['unittype'])
        self.label_warehouse.setText(
            self.ori_detail['warehouseid'] + ' ' +
            self.ori_detail['warehousename']
        )
        self.comboBox_dpposition.setCurrentText(self.ori_detail['dpposition'])
        self.comboBox_piposition.setCurrentText(self.ori_detail['position'])
        self.pushButton_applyer.setText(
            self.ori_detail['piapplyerid'] + ' ' +
            self.ori_detail['piapplyername']
        )
        self.pushButton_qa.setSign(
            True, self.ori_detail['piqaid'] + ' ' + self.ori_detail['piqaname']
        )
        self.pushButton_dpwsman.setText(
            self.ori_detail['dpwarehousemanid'] + ' ' +
            self.ori_detail['dpwarehousemanname']
        )
        self.pushButton_piwsman.setSign(
            True, self.ori_detail['warehousemanid'] + ' ' +
            self.ori_detail['warehousemanname']
        )

        self.lineEdit_amount.setText(str(self.ori_detail['dpamount']))
        self.lineEdit_oddment.setText(str(self.ori_detail['oddment']))
        self.label_unit.setText(self.units[self.ori_detail['unittype']])
        self.label_oddmentunit.setText(self.units[3])

        self.label_dpamount.setText(str(self.ori_detail['piamount']))
        self.label_piamount.setText(str(self.ori_detail['piamount']))

        if self.ori_detail['pistatus'] == 0:
            self.pushButton_accept.setVisible(True)
            self.pushButton_save.setVisible(True)
            self.pushButton_cancel.setVisible(False)
            self.pushButton_dp.setVisible(False)
            self.pushButton_pi.setVisible(False)
        elif self.ori_detail['pistatus'] == 1:
            self.pushButton_accept.setVisible(False)
            self.pushButton_save.setVisible(False)
            self.pushButton_cancel.setVisible(True)
            self.pushButton_dp.setVisible(True)
            self.pushButton_pi.setVisible(False)
        elif self.ori_detail['pistatus'] == 2:
            self.pushButton_accept.setVisible(False)
            self.pushButton_save.setVisible(False)
            self.pushButton_cancel.setVisible(False)
            self.pushButton_dp.setVisible(False)
            self.pushButton_pi.setVisible(True)
        elif self.ori_detail['pistatus'] == 3:
            self.pushButton_accept.setVisible(False)
            self.pushButton_save.setVisible(False)
            self.pushButton_cancel.setVisible(False)
            self.pushButton_dp.setVisible(False)
            self.pushButton_pi.setVisible(False)

    def get_oddment(self):
        self.treeWidget_oddments.clear()
        self.treeWidget_oddments.hideColumn(0)
        values_list = (
            "autoid", "batchno", "amount", "unit", "makedate", "ppid"
        )
        key_dict = {
            'dppid': self.ppid
        }
        res = self.PC.get_oddmentdrawnotes(False, *values_list, **key_dict)
        if not len(res):
            return

        for item in res:
            if item['unit'] not in self.units:
                continue
            qtreeitem = QTreeWidgetItem(self.treeWidget_oddments)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['batchno'])
            qtreeitem.setText(2, str(item['amount']))
            qtreeitem.setText(3, item['unit'])
            qtreeitem.setText(4, str(self.a_box_samount - item['amount']))
            qtreeitem.setText(5, str(item['makedate']))
            self.oddments_list.append(
                (2, self.ppid, self.a_box_samount,
                 item['ppid'], item['amount'])
            )
        for i in range(1, 6):
            self.treeWidget_oddments.resizeColumnToContents(i)
        if self.treeWidget_oddments.topLevelItemCount() > 0:
            self.checkBox_has_draw_oddments.setCheckState(2)

    @pyqtSlot(int)
    def on_comboBox_unittype_currentIndexChanged(self, p_int):
        self.label_unit.setText(self.units[p_int])
        try:
            if p_int != self.ori_detail['unittype']:
                self.new_detail['unittype'] = p_int
            else:
                try:
                    del self.new_detail['unittype']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['unittype'] = p_int
        self.set_total_amount()

    @pyqtSlot(str)
    def on_lineEdit_amount_textEdited(self, p_str):
        if p_str == '':
            amount = decimal.Decimal('0')
        else:
            amount = decimal.Decimal(p_str)
        try:
            if amount != self.ori_detail['dpamount']:
                self.new_detail['dpamount'] = amount
            else:
                try:
                    del self.new_detail['dpamount']
                except KeyError:
                    pass

            self.set_total_amount()

        except KeyError:
            self.new_detail['dpamount'] = amount
        except decimal.InvalidOperation:
            pass

    def set_total_amount(self):
        if self.lineEdit_amount.text() != '':
            amount = decimal.Decimal(self.lineEdit_amount.text())
        else:
            amount = decimal.Decimal('0')
        if self.lineEdit_oddment.text() != '':
            oddment = decimal.Decimal(self.lineEdit_oddment.text())
        else:
            oddment = decimal.Decimal('0')
        unit_index = self.comboBox_unittype.currentIndex()
        this_batchno_amount = 0
        if unit_index == 0:
            this_batchno_amount = amount * self.a_box_samount + oddment
        elif unit_index == 1:
            this_batchno_amount = amount * self.mpamount * self.spamount + oddment
        elif unit_index == 2:
            this_batchno_amount = amount * self.spamount + oddment
        elif unit_index == 3:
            this_batchno_amount = amount + oddment
        merge_amount = self.treeWidget_oddments.topLevelItemCount() * \
                       self.a_box_samount
        piamount = this_batchno_amount + merge_amount
        self.label_dpamount.setText(str(piamount))
        self.label_piamount.setText(str(piamount))
        try:
            if piamount != self.ori_detail['piamount']:
                self.new_detail['piamount'] = piamount
            else:
                try:
                    del self.new_detail['piamount']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['piamount'] = piamount

    @pyqtSlot(str)
    def on_lineEdit_oddment_textEdited(self, p_str):
        if p_str == '':
            amount = decimal.Decimal('0')
        else:
            amount = decimal.Decimal(p_str)
        try:
            if amount != self.ori_detail['oddment']:
                self.new_detail['oddment'] = amount
            else:
                try:
                    del self.new_detail['oddment']
                except KeyError:
                    pass
            self.set_total_amount()
        except KeyError:
            self.new_detail['oddment'] = amount
        except decimal.InvalidOperation:
            pass

    @pyqtSlot(bool, str)
    def on_pushButton_qa_signChanged(self, p_bool, p_str):
        if p_bool:
            self.pushButton_accept.setEnabled(True)
            piqaid, piqaname = p_str.split(' ')
        else:
            self.pushButton_accept.setEnabled(False)
            piqaid, piqaname = ('', '')
        try:
            if piqaid != self.ori_detail['piqaid']:
                self.new_detail['piqaid'] = piqaid
                self.new_detail['piqaname'] = piqaname
            else:
                try:
                    del self.new_detail['piqaid']
                    del self.new_detail['piqaname']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['piqaid'] = piqaid
            self.new_detail['piqaname'] = piqaname

    @pyqtSlot(bool, str)
    def on_pushButton_applyer_signChanged(self, p_bool, p_str):
        if p_bool:
            piapplyerid, piapplyername = p_str.split(' ')
        else:
            piapplyerid, piapplyername = ('', '')
        try:
            if piapplyerid != self.ori_detail['piapplyerid']:
                self.new_detail['piapplyerid'] = piapplyerid
                self.new_detail['piapplyername'] = piapplyername
            else:
                try:
                    del self.new_detail['piapplyerid']
                    del self.new_detail['piapplyername']
                except KeyError:
                    pass
        except KeyError:
            self.new_detail['piapplyerid'] = piapplyerid
            self.new_detail['piapplyername'] = piapplyername

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

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

    @pyqtSlot()
    def on_pushButton_save_clicked(self):
        if self.has_changed():
            self.WC.update_productputinnote(self.autoid, **self.new_detail)

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if self.pushButton_applyer.text() in ('', ' '):
            self.pushButton_applyer.setSign(
                True, user.user_id + ' ' +user.user_name
            )
            self.new_detail['piapplyerid'] = user.user_id
            self.new_detail['piapplyername'] = user.user_name
            self.new_detail['dpdate'] = user.now_date
        self.new_detail['pistatus'] = 1

        self.WC.update_productputinnote(self.autoid, **self.new_detail)
        realamount = decimal.Decimal(self.label_piamount.text())
        detail = {'realamount': realamount}
        self.PC.update_producingplan(self.ppid, **detail)

        self.pushButton_save.setVisible(False)
        self.pushButton_accept.setVisible(False)
        self.pushButton_cancel.setVisible(True)
        self.pushButton_dp.setVisible(False)
        self.pushButton_pi.setVisible(False)
        self.accepted.emit()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.new_detail['piapplyerid'] = ''
        self.new_detail['piapplyername'] = ''
        self.new_detail['pistatus'] = 0

        self.WC.update_productputinnote(self.autoid, **self.new_detail)

        self.pushButton_save.setVisible(True)
        self.pushButton_accept.setVisible(True)
        self.pushButton_cancel.setVisible(False)
        self.pushButton_dp.setVisible(False)
        self.pushButton_pi.setVisible(False)
        self.accepted.emit()

    @pyqtSlot()
    def on_pushButton_dp_clicked(self):
        self.new_detail['dpwarehousemanid'] = user.user_id
        self.new_detail['dpwarehousemanname'] = user.user_name
        self.new_detail['pistatus'] = 2

        self.WC.update_productputinnote(self.autoid, **self.new_detail)

        self.pushButton_save.setVisible(False)
        self.pushButton_accept.setVisible(False)
        self.pushButton_cancel.setVisible(False)
        self.pushButton_dp.setVisible(False)
        self.pushButton_pi.setVisible(True)
        self.accepted.emit()

    @pyqtSlot()
    def on_pushButton_pi_clicked(self):
        if self.label_checkstatus.text() != '检验合格':
            mesgbox = MessageBox(
                parent=self, title="提示", text="当前产品尚未检验合格无法入库"
            )
            mesgbox.exec()
            return
        self.new_detail['warehousemanid'] = user.user_id
        self.new_detail['warehousemanname'] = user.user_name
        self.new_detail['pidate'] = user.now_date
        self.new_detail['pistatus'] = 3
        # 计算要入库的产品信息
        putin_msg = self.get_putin_msg()
        self.WC.update_productputinnote(self.autoid, True, putin_msg, **self.new_detail)

        self.pushButton_save.setVisible(False)
        self.pushButton_accept.setVisible(False)
        self.pushButton_cancel.setVisible(False)
        self.pushButton_dp.setVisible(False)
        self.pushButton_pi.setVisible(False)
        self.accepted.emit()

    def get_putin_msg(self):
        return_detail = []
        return_detail += self.oddments_list
        # 全部的入库数量
        all_amount = decimal.Decimal(self.label_piamount.text())
        # 本批零头数量
        if self.lineEdit_oddment.text() not in ('', '0'):
            oddment_amount = decimal.Decimal(self.lineEdit_oddment.text())
            return_detail.append((1, self.ppid, oddment_amount, 0, 0))
        else:
            oddment_amount = 0
        # 合箱数量
        merge_amount = decimal.Decimal(self.treeWidget_oddments.topLevelItemCount()) * self.a_box_samount

        # 本批整箱数量
        spamount_of_total_box = all_amount - oddment_amount - merge_amount
        return_detail.append((0, self.ppid, spamount_of_total_box,0 ,0))
        return return_detail

    def has_changed(self):
        if not len(self.new_detail):
            return False
        if self.pushButton_applyer.text() in ('', ' '):
            self.pushButton_applyer.setSign(
                True, user.user_id + ' ' +user.user_name
            )
            self.new_detail['piapplyerid'] = user.user_id
            self.new_detail['piapplyername'] = user.user_name
        return True
class EditSampleRecordDetailModule(QDialog, Ui_Dialog):
    def __init__(self, autoid, parent=None):
        super(EditSampleRecordDetailModule, self).__init__(parent)
        self.setupUi(self)
        if '50' not in user.powers:
            self.close()
        if user.powers['10'] == 0:
            self.close()
        self.power = '{:03b}'.format(user.powers['10'])
        if self.power[1] == '0':
            self.pushButton_accept.setVisible(False)
            self.pushButton_cancel.setVisible(False)
        self.autoid = autoid
        self.checkitem_id = None
        self.ori_detail = object
        self.new_detail = {}
        self.lr_list = []
        self.LC = LabrecordsController()
        self.PC = ProductController()

        self.get_detail()
        self.get_observation_record()
        self.get_labrecord_list()

    def get_detail(self):
        condition = {'autoid': self.autoid}
        res = self.LC.get_data(6, False, **condition)
        if len(res) != 1:
            self.pushButton_accept.setEnabled(False)
            self.pushButton_cancel.setEnabled(False)
            return
        self.ori_detail = res[0]
        self.lineEdit_product.setText(self.ori_detail.ppid.prodid + ' ' +
                                      self.ori_detail.ppid.prodname)
        self.lineEdit_commonname.setText(self.ori_detail.ppid.commonname)
        self.lineEdit_batchno.setText(self.ori_detail.ppid.batchno)
        self.lineEdit_spec.setText(self.ori_detail.ppid.spec)
        self.lineEdit_package.setText(self.ori_detail.ppid.package)
        self.lineEdit_makedate.setText(str(self.ori_detail.ppid.makedate))
        self.lineEdit_samplequantity.setText(
            str(self.ori_detail.samplequantity))
        self.lineEdit_unit.setText(self.ori_detail.unit)
        self.comboBox_kind.setCurrentIndex(self.ori_detail.kind)
        if self.ori_detail.status != 0:
            self.pushButton_accept.setEnabled(False)
            self.pushButton_cancel.setEnabled(False)

    def get_observation_record(self):
        self.treeWidget_observation.clear()
        condition = {'srid': self.autoid}
        res = self.LC.get_data(7, False, **condition)

        if not len(res):
            return
        lrid_list = res.values_list(*VALUES_TUPLE_LRID, flat=True)
        condition_lr = {'ciid__in': lrid_list, 'labtype': 6}
        self.lr_list = self.LC.get_data(0, False, *VALUES_TUPLE_LR,
                                        **(condition_lr))

        for item in res.values(*VALUES_TUPLE_OB):
            qtreeitem = QTreeWidgetItem(self.treeWidget_observation)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(2, item['obsperiod'])
            qtreeitem.setText(3, str(item['obsdate']))
            qtreeitem.setText(4, str(item['samplequantity']))
            qtreeitem.setText(5, item['unit'])
            qtreeitem.setText(6, item['conclusion'])
            for it in self.lr_list:
                if it['ciid'] == item['autoid']:
                    qtreeitem.setText(1, str(it['autoid']))
                    qtreeitem.setText(7, STATUS[it['status']])
                    break
        for i in range(2, 8):
            self.treeWidget_observation.resizeColumnToContents(i)

    def get_labrecord_list(self):
        self.treeWidget_labrecord.clear()
        if self.ori_detail is None:
            return
        for item in self.lr_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_labrecord)
            qtreeitem.setText(0, str(item['autoid']))
            qtreeitem.setText(1, item['paperno'])
            qtreeitem.setText(2, str(item['reportdate']))
            qtreeitem.setText(3, STATUS[item['status']])

    @pyqtSlot(QPoint)
    def on_treeWidget_observation_customContextMenuRequested(self, pos):
        if self.ori_detail is None:
            return
        if self.ori_detail.status != 0:
            return
        current_item = self.treeWidget_observation.currentItem()
        menu = QMenu()
        action_1 = menu.addAction("增加")
        action_2 = menu.addAction("修改")
        action_3 = menu.addAction("删除")
        menu.addSeparator()
        action_4 = menu.addAction("提交请验")
        action_5 = menu.addAction("取消请验")
        global_pos = self.treeWidget_observation.mapToGlobal(pos)
        action = menu.exec(global_pos)
        if action == action_1:
            unit = self.lineEdit_unit.text()
            detail = EditObservationModule(srid=self.autoid,
                                           unit=unit,
                                           parent=self)
            detail.accepted.connect(self.get_observation_record)
            detail.show()
        elif action == action_2:
            if current_item is None:
                return
            id = int(current_item.text(0))
            detail = EditObservationModule(autoid=id, parent=self)
            detail.accepted.connect(self.get_observation_record)
            detail.show()
        elif action == action_3:
            if current_item is None:
                return
            condition = {'autoid': int(current_item.text(0))}
            self.LC.delete_data(7, condition)
            lrid = current_item.text(1)
            if lrid != '':
                self.LC.delete_labrecord_and_detail(int(lrid))
            self.get_observation_record()
        elif action == action_4:
            if self.ori_detail is None or current_item is None:
                return
            if current_item.text(1) == '':
                if self.checkitem_id is None:
                    prodid = self.ori_detail.ppid.prodid
                    condition = {'prodid': prodid}
                    res = self.PC.get_data(1, True, *VALUES_TUPLE_PD,
                                           **condition)
                    if not len(res):
                        return
                    self.checkitem_id = res[0]
                kwargs = {
                    'labtype': 6,
                    'chkid': self.ori_detail.ppid.prodid,
                    'chkname': self.ori_detail.ppid.prodname,
                    'batchno': self.ori_detail.ppid.batchno,
                    'spec': self.ori_detail.ppid.spec,
                    'package': self.ori_detail.ppid.package,
                    'ciid': int(current_item.text(0)),
                    'createdate': user.now_date,
                    'checkamount': self.ori_detail.samplequantity,
                    'caunit': self.ori_detail.unit,
                    'sampleamount': decimal.Decimal(current_item.text(4)),
                    'sampleunit': current_item.text(5),
                }
                lrid = self.LC.create_labrecord(self.checkitem_id, 6,
                                                user.now_date, **kwargs)
            else:
                lrid = int(current_item.text(1))
            detail = ApplycheckModule(lrid, 6, self)
            detail.rejected.connect(lambda: self.delete_check_report(lrid))
            detail.applyed.connect(detail.accept)
            detail.accepted.connect(self.get_observation_record)
            detail.accepted.connect(self.get_labrecord_list)
            detail.show()
        elif action == action_5:
            if current_item is None:
                return
            lrid = current_item.text(1)
            if lrid != '':
                self.LC.delete_labrecord(int(lrid))
                self.get_observation_record()
        else:
            pass

    def delete_check_report(self, lrid):
        self.LC.delete_labrecord(lrid)
        self.get_observation_record()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_observation_itemDoubleClicked(self, qtreeitem, p_int):
        id = int(qtreeitem.text(0))
        detail = EditObservationModule(autoid=id, parent=self)
        detail.accepted.connect(self.get_observation_record)
        detail.show()

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_labrecord_itemDoubleClicked(self, qtreeitem, p_int):
        if self.power[1] == '0':
            return
        id = int(qtreeitem.text(0))
        detail = CheckreportModule(id, True, self)
        detail.show()

    @pyqtSlot(str)
    def on_lineEdit_samplequantity_textChanged(self, p_str):
        p_data = decimal.Decimal(p_str)
        try:
            if p_data != self.ori_detail.samplequantity:
                self.new_detail['samplequantity'] = p_data
            else:
                try:
                    del self.new_detail['samplequantity']
                except KeyError:
                    pass
        except ValueError:
            self.new_detail['samplequantity'] = p_data

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

    @pyqtSlot(int)
    def on_comboBox_kind_currentIndexChanged(self, p_int):
        try:
            if p_int != self.ori_detail.kind:
                self.new_detail['kind'] = p_int
            else:
                try:
                    del self.new_detail['kind']
                except KeyError:
                    pass
        except ValueError:
            self.new_detail['kind'] = p_int

    @pyqtSlot()
    def on_pushButton_accept_clicked(self):
        if not len(self.new_detail):
            return
        condiition = {'autoid': self.autoid}
        self.LC.update_data(6, condiition, **self.new_detail)
        self.accept()

    @pyqtSlot()
    def on_pushButton_cancel_clicked(self):
        self.close()
Esempio n. 30
0
class HomePageModule(QWidget, Ui_Form):

    def __init__(self, autoid, parent=None):
        super(HomePageModule, self).__init__(parent)
        self.setupUi(self)
        self.autoid=autoid
        self.current_img = object
        self.current_page = object
        self.PC = ProductController()
        self.WC = WorkshopController()
        self.IC = ImageController()
        # 自动缩放
        self.label_image.setScaledContents(True)
        self.get_detail()
        self.get_images()
        self.scrollArea.setVisible(False)
        self.groupBox.setVisible(False)

    def get_detail(self):
        key_dict = {'autoid': self.autoid}
        res = self.PC.get_producingplan(False, *VALUES_TUPLE_PP, **key_dict)
        if not len(res):
            return
        pp_detail = res[0]
        self.label_product.setText(pp_detail['prodid'] + pp_detail['prodname'])
        self.label_commonname.setText(pp_detail['commonname'])
        self.label_spec.setText(pp_detail['spec'])
        self.label_package.setText(pp_detail['package'])
        self.label_batchno.setText(pp_detail['batchno'])
        self.label_realamout.setText(
            to_str(pp_detail['realamount']) + pp_detail['spunit']
        )
        self.label_makedate.setText(str(pp_detail['makedate']))

    def get_images(self):
        self.treeWidget_imagenamelist.clear()
        self.treeWidget_imagenamelist.hideColumn(0)
        key_dict = {'ppid': self.autoid}
        imgid_list = self.WC.get_plids(True,*VALUES_TUPLE_PLIB, **key_dict)
        if not len(imgid_list):
            return

        for item in imgid_list:
            qtreeitem = QTreeWidgetItem(self.treeWidget_imagenamelist)
            qtreeitem.setText(0, str(item['imgid']))
            qtreeitem.setText(1, str(item['title']))
            qtreeitem.setText(2, str(item['ext']))
        self.treeWidget_imagenamelist.resizeColumnToContents(1)

    @pyqtSlot(QTreeWidgetItem, int)
    def on_treeWidget_imagenamelist_itemDoubleClicked(self, qtreeitem, p_int):
        self.scrollArea.setVisible(True)
        self.groupBox.setVisible(True)
        img_id = int(qtreeitem.text(0))
        ext = qtreeitem.text(2).lower()
        key_dict = {
            'autoid': img_id
        }
        img_list = self.IC.get_image(False, *VALUES_TUPLE_IMG, **key_dict)
        if not len(img_list):
            return
        image = img_list[0]
        if ext == 'pdf':
            self.comboBox_jumpto.setVisible(True)
            self.pushButton_prepage.setVisible(True)
            self.pushButton_nextpage.setVisible(True)
            self.current_img = fitz.Document(stream=image['img'],
                                             filetype='pdf')
            page_count = self.current_img.pageCount
            page_list = []
            self.comboBox_jumpto.clear()
            for i in range(1, page_count + 1):
                page_list.append('第' + str(i) + '页')
            self.comboBox_jumpto.addItems(page_list)
            self.current_page = self.current_img.loadPage(0)

        else:
            self.comboBox_jumpto.setVisible(False)
            self.pushButton_prepage.setVisible(False)
            self.pushButton_nextpage.setVisible(False)
            img = QImage.fromData(image['img'])
            self.current_img = QPixmap.fromImage(img)
            self.label_image.setPixmap(self.current_img)

        # 默认放大为3被,同时自动调用on_horizontalSlider_zoom_valueChanged
        self.horizontalSlider_zoom.setValue(30)

    @pyqtSlot(int)
    def on_horizontalSlider_zoom_valueChanged(self, p_int):

        try:
            self.label_zoom.setText(str(p_int * 10) + '%')
            # 把当前页面转为QPixmap,并缩放为p_int/10
            cover = render_pdf_page(self.current_page, p_int / 10, p_int / 10)
            self.label_image.setPixmap(cover)
        except AttributeError:
            size = self.current_img.size()
            new_pixmap = self.current_img.scaled(size.width() * p_int / 10,
                                                 size.height() * p_int / 10)
            self.label_image.setPixmap(new_pixmap)

    @pyqtSlot(int)
    def on_comboBox_jumpto_currentIndexChanged(self, p_int):
        try:
            self.current_page = self.current_img.loadPage(p_int)
            self.on_horizontalSlider_zoom_valueChanged(
                self.horizontalSlider_zoom.value())
        except (AttributeError, ValueError):
            pass

    @pyqtSlot()
    def on_pushButton_prepage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index - 1 >= 0:
            try:
                self.current_page = self.current_img.loadPage(index - 1)
                self.comboBox_jumpto.setCurrentIndex(index - 1)
            except (AttributeError, ValueError):
                pass

    @pyqtSlot()
    def on_pushButton_nextpage_clicked(self):
        index = self.comboBox_jumpto.currentIndex()
        if index + 1 < self.comboBox_jumpto.count():
            try:
                self.current_page = self.current_img.loadPage(index + 1)
                self.comboBox_jumpto.setCurrentIndex(index + 1)
            except (AttributeError, ValueError):
                pass