Exemple #1
0
 def _remove_second_service(self):
     service_id = get_table_current_index_info(self.second_service_table, 2)
     if service_id:
         service_name = get_table_current_index_info(self.second_service_table, 3)
         reply = QtWidgets.QMessageBox.question(self.remove_second_service, 'Message',
                                                "是否删除此服务项目:" + service_name + "?",
                                                QtWidgets.QMessageBox.Yes,
                                                QtWidgets.QMessageBox.No)
         if reply == QtWidgets.QMessageBox.Yes:
             if stock_handler.get_count_by_service(service_id):
                 QtWidgets.QMessageBox.information(self.remove_second_service, "提示", "该服务项目存在库存信息,不允许删除!")
                 return
             else:
                 try:
                     db_transaction_util.begin()
                     service_handler.delete_service_all_attribute(service_id)
                     service_handler.delete_service(service_id)
                     db_transaction_util.commit()
                     QtWidgets.QMessageBox.information(self.remove_second_service, "提示", "删除成功!")
                     self._refresh_second_service()
                 except Exception as e:
                     print(e)
                     db_transaction_util.rollback()
                     QtWidgets.QMessageBox.information(self.remove_second_service, "提示", "删除失败,请重试!")
     else:
         QtWidgets.QMessageBox.information(self.remove_second_service, "提示", "请选择二级服务项目")
    def do_pay(self):

        unpaid = Decimal(self.unpaid.text())
        if unpaid < 0:
            QMessageBox.information(self.payButton, '提示', '付款额度超过未付款额度,请重新填写!')
            return
        pay = Decimal(self.pay.text())
        note = self.notes.text()
        paid = Decimal(self.paid.text())
        new_paid = paid + pay
        try:
            db_transaction_util.begin()

            # 新增付款明细
            self._add_payment_detail(new_paid, unpaid)
            # 更新进货付款信息
            self._update_buy_pay_info(new_paid, unpaid, note)

            db_transaction_util.commit()

            QMessageBox.information(self.payButton, '提示', '付款成功!')
            self.close()

        except Exception as e:
            print(e)
            db_transaction_util.rollback()
            QMessageBox.information(self.payButton, '提示', '付款失败!')
Exemple #3
0
    def do_update(self):
        attr_id = table_utils.get_table_current_index_info(self.tableView, 0)
        if not attr_id:
            QMessageBox.information(self.add, '提示', '请选择一条属性进行修改!')
            return
        attr_id = int(attr_id)
        old_attr_name = table_utils.get_table_current_index_info(
            self.tableView, 1)

        new_attr_name, ok = QInputDialog.getText(self.edit, '修改属性', '请修改属性名称',
                                                 QLineEdit.Normal,
                                                 old_attr_name)

        if new_attr_name and ok:
            exists_info = attribute_handler.get_count_by_name(new_attr_name)
            if exists_info:
                if not exists_info[1]:
                    QMessageBox.information(self.edit, '提示', '该属性已经存在,请重新输入')
                    return
                else:
                    try:
                        db_transaction_util.begin()

                        # 将原来的属性对应的销售信息更新到当前的属性ID上
                        sale_item_handler.update_item_id(
                            exists_info[2], attr_id)
                        # 物理删除原来的属性
                        attribute_handler.delete_attribute_physical(
                            exists_info[2])
                        # 修改新的属性名称
                        attribute_handler.update_attribute(
                            attr_id, new_attr_name)

                        db_transaction_util.commit()
                    except Exception as e:
                        print(e)
                        db_transaction_util.rollback()
                        QMessageBox.information(self.edit, '提示',
                                                '该属性名称修改失败,请重新提交!')
            else:
                try:
                    attribute_handler.update_attribute(attr_id, new_attr_name)
                    QMessageBox.information(self.edit, '提示', '新增成功')
                    self._init_table()
                except Exception as e:
                    print(e)
                    QMessageBox.information(self.edit, '提示',
                                            '该属性名称修改失败,请重新提交!')
    def _update(self):
        name = self.service_name.text()
        if '-' in name:
            QtWidgets.QMessageBox.information(self.submit, "提示",
                                              "名字输入有误,请勿添加\"-\"符号")
        elif name == "":
            QtWidgets.QMessageBox.information(self.submit, "提示", "请输入名称")
        else:
            try:
                db_transaction_util.begin()
                if self.service_id:
                    if self.name != name:
                        service_handler.update_service(self.service_id, name)
                        stock_handler.update_second_service_name(
                            self.service_id, name)
                else:
                    self.service_id = service_handler.add_second_level_service(
                        name, father_id=self.father_id)

                for k, v in self.checkbox_dict.items():
                    if v.checkState() == Qt.Checked:
                        if k not in self.checked_dict:
                            attr_item = ServiceItem()
                            attr_item.service_id(self.service_id).attribute_id(
                                k).attribute_name(v.text())
                            attr_item.create_time(
                                time_utils.get_now()).create_op(
                                    config.login_user_info[0])
                            service_handler.add_service_attribute(attr_item)
                    else:
                        if k in self.checked_dict:
                            service_handler.delete_service_attribute(
                                self.service_id, k)
                db_transaction_util.commit()

                QtWidgets.QMessageBox.information(self.submit, "提示", "提交成功")
                self.close()
            except Exception as db_excption:
                print(db_excption)
                db_transaction_util.rollback()
                QtWidgets.QMessageBox.information(self.submit, "提示",
                                                  "服务项目更新失败,请重试")
    def do_bulk_pay(self):
        notes = self.note.text()

        try:
            db_transaction_util.begin()
            for buy_info in self.buys:
                # 新增付款明细
                self._add_payment_detail(buy_info[1], buy_info[2], buy_info[0])
                # 更新进货付款信息
                self._update_buy_pay_info(buy_info[1], buy_info[2], notes,
                                          buy_info[0])

            db_transaction_util.commit()

            QMessageBox.information(self.payButton, '提示', '付款成功!')
            self.close()

        except Exception as e:
            print(e)
            db_transaction_util.rollback()
            QMessageBox.information(self.payButton, '提示', '付款失败!')
    def do_write_off(self):
        if not self.sale_id:
            QMessageBox.information(self.writeOffButton, "提示", '请选择需要销负的记录!')
            return
        msg = self._check_required()
        if msg:
            QMessageBox.information(self.writeOffButton, "提示", msg)
            return
        brand_name = self.brand.text()
        model_name = self.model.text()
        buy_number = self.buy_number.value()
        price = Decimal(self.price.text())
        paid = self.paid.text()
        if paid:
            paid = Decimal(paid)
        else:
            paid = Decimal(0.0)
        unpaid = Decimal(self.unpaid.text())
        total = Decimal(self.total.text())
        note = self.note.text()
        payment = int(self.payment.currentData())
        buy_date = self.buy_date.date().toString('yyyy-MM-dd')

        try:
            db_transaction_util.begin()

            # 更新库存中的商品信息
            brand_id = self._get_brand(brand_name)
            model_id = self._get_model(brand_id, model_name)
            stock_handler.update_brand_name(self.stock_id, brand_name)
            stock_handler.update_brand_id(self.stock_id, brand_id)
            stock_handler.update_model_name(self.stock_id, model_name)
            stock_handler.update_model_id(self.stock_id, model_id)

            # 更新库存
            self._update_stock_info(self.stock_id, buy_number, total)

            # 新增进货信息
            supplier_id = self._get_supplier(self.supplier.text())
            buy_id = self._add_buy_info(self.stock_id, supplier_id, price,
                                        buy_number, buy_date, unpaid, paid,
                                        total, payment, note, self.balance)

            # 新增进货库存明细
            self._add_stock_detail(self.stock_id, buy_id, total, buy_number)

            # 更新销售库存明细状态
            stock_detail_handler.update_negative_info(self.sale_id, total)

            # 更新供应商付款信息
            self._add_supplier_payment_detail(buy_id, supplier_id, paid,
                                              unpaid, payment)

            db_transaction_util.commit()
            QMessageBox.information(self.writeOffButton, "提示", '销负成功!')
            self._clear_detail()
            self._init_write_off_table()
        except Exception as e:
            print(e)
            db_transaction_util.rollback()
            QMessageBox.information(self.writeOffButton, "提示",
                                    '销负失败,请重试!\n' + e.__str__())
Exemple #7
0
    def do_add(self):
        succeeded_list = '成功添加:'
        failed_dict = OrderedDict()
        for row_index in range(1, self.line_number + 1):
            # 如果没有这个对应的序号属性,则说明已经删除,继续处理下一条记录
            if not hasattr(self, 'seq_' + str(row_index)):
                continue

            line_number = getattr(self, 'seq_' + str(row_index)).text()
            msg = self._check_required(line_number)
            # 如果必填检查不通过,则将错误信息记录下来,继续处理下一条记录
            if msg:
                failed_dict[line_number] = msg
                continue

            # 提取所有表单项的值
            buy_date = getattr(self, 'buy_date_' + line_number).date().toString('yyyy-MM-dd')
            brand = getattr(self, 'brand_' + line_number).text()
            model = getattr(self, 'model_' + line_number).text()
            supplier = getattr(self, 'supplier_' + line_number).text()

            unit = getattr(self, 'unit_' + line_number).text()
            price = Decimal(getattr(self, 'price_' + line_number).text())
            number = getattr(self, 'number_' + line_number).value()
            total = Decimal(getattr(self, 'total_' + line_number).text())
            paid_value = getattr(self, 'paid_' + line_number).text()
            paid = Decimal(paid_value if paid_value else '0.0')
            unpaid = Decimal(getattr(self, 'unpaid_' + line_number).text())
            note = getattr(self, 'note_' + line_number).text()
            payment = int(getattr(self, 'payment_' + line_number).currentData())

            try:
                db_transaction_util.begin()

                brand_id = self._get_brand(brand)

                model_id = self._get_model(brand_id, model)

                supplier_id = self._get_supplier(supplier)

                stock_info = stock_handler.get_stock_by_model(model_id)

                # 如果通过型号找到库存,则单位属性沿用库存中的单位,并更新库存总额和库存量
                if stock_info:
                    stock_id = stock_info[0]
                    self._update_stock_info(stock_id, number, total)
                else:
                    # 新增库存信息
                    stock_id = self._add_stock_info(model, brand, model_id, brand_id, line_number, total, number, unit)

                # 新增进货信息
                buy_id = self._add_buy_info(stock_id, supplier_id, price, number, buy_date, unpaid, paid, total,
                                            payment, note)

                # 如果是退货,更新原来的进货信息中剩余量
                if number < 0:
                    self._update_buy_left(stock_id, number)
                    self._update_buy_unpaid(stock_id, total)

                # 新增库存明细
                self._add_stock_detail(stock_id, buy_id, total, number)

                # 新增供应商支付信息,如果数量大于0,则为进货,小于零则为退货
                self._add_supplier_payment_detail(buy_id, supplier_id, paid, unpaid, payment, number < 0)

                db_transaction_util.commit()
                succeeded_list = succeeded_list + '第' + line_number + '行、'
            except Exception as e:
                print(e)
                failed_dict[line_number] = e.__str__()
                db_transaction_util.rollback()

        failed_info = '未录入成功的行数:'
        for key in list(failed_dict.keys()):
            failed_info += '第' + key + '数据:' + failed_dict[key]

        succeeded_list += '\n' + failed_info
        QMessageBox.information(self.submit, '提示', succeeded_list)