Beispiel #1
0
    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(paid, unpaid)
            # 更新进货付款信息
            self._update_buy_pay_info(new_paid, unpaid, note)
            # 更新供应商未付信息
            self._update_supplier_unpaid(pay)

            db_transaction_util.commit()

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

        except Exception as e:
            logger.error(e.__str__())
            logger.error('traceback.format_exc():\n{}'.format(
                traceback.format_exc()))
            db_transaction_util.rollback()
            QMessageBox.information(self.payButton, '提示', '付款失败!')
Beispiel #2
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:
             stock_num = stock_handler.get_count_by_service(service_id)
             if stock_num and stock_num[0]:
                 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, "提示",
                                           "请选择二级服务项目")
Beispiel #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, '提示',
                                            '该属性名称修改失败,请重新提交!')
Beispiel #4
0
    def _submit(self):
        money_changed = self.money_changed.text()
        balance_changed = self.balance_changed.text()
        if not money_changed or not balance_changed:
            QMessageBox.information(self.addButton, '提示', '调整金额和调整数量不能为空!')
            self.balance_changed.setFocus()
            return
        money_changed = Decimal(money_changed)
        balance_changed = int(balance_changed)

        if money_changed == self.original_cost and balance_changed == self.original_balance:
            QMessageBox.information(self.addButton, '提示', '金额和数量未做调整,请重新填写!')
            self.balance_changed.setFocus()
            return

        changed_number = balance_changed - self.original_balance
        changed_cost = money_changed - self.original_cost
        buy_date = self.calibration_date.date().toString('yyyy-MM-dd')
        payment_method = list(Payment.get_payment_method().keys())[0]
        note = self.notes.text()
        create_op = int(self.staffComb.currentData())
        try:
            db_transaction_util.begin()
            logger.info('新增库存校准数据')
            buy_id = buy_service.add_buy_info(self.stock_id, 9999, 0.0,
                                              changed_number, buy_date, 0.0,
                                              0.0, changed_cost,
                                              payment_method, note, 0,
                                              create_op, BuyInfo.calibrated(),
                                              BuyInfo.under_reviewed())
            if changed_number >= 0:
                change_type = StockDetail.by_increased()
            else:
                change_type = StockDetail.by_decreased()

            stock_service.add_stock_detail(self.stock_id, buy_id,
                                           abs(changed_cost),
                                           abs(changed_number), change_type)
            db_transaction_util.commit()
            logger.info('库存校准数据新增完成')
            QMessageBox.information(self.addButton, '提示', '库存校准成功,请等待数据审核!')
            self.close()
        except Exception as e:
            db_transaction_util.rollback()
            logger.error(e)
            logger.error('traceback.format_exc():\n{}'.format(
                traceback.format_exc()))
Beispiel #5
0
    def do_review(self):
        review_id = table_utils.get_table_current_index_info(self.tableView, 0)
        if not review_id:
            QMessageBox.information(self.reviewButton, '提示', '请选择待审核的库存校准数据!')
            return
        stock_id = int(
            table_utils.get_table_current_index_info(self.tableView, 1))
        stock_detail = stock_detail_handler.get_calibration_detail_by_buy_id(
            review_id)
        changed_type = stock_detail['type']

        answer = QMessageBox.information(
            self.reviewButton, '校准审核', '是否审核通过该项库存校准?',
            QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
            QMessageBox.Yes)
        try:
            db_transaction_util.begin()
            if answer == QMessageBox.Yes:

                changed_cost = Decimal(
                    table_utils.get_table_current_index_info(
                        self.tableView, 9))
                changed_number = int(
                    table_utils.get_table_current_index_info(
                        self.tableView, 7))

                if changed_type == StockDetail.by_decreased():
                    buy_service.decrease_buy_left(stock_id,
                                                  abs(changed_number))
                else:
                    buy_service.increase_buy_left(stock_id,
                                                  abs(changed_number))

                stock_handler.update_stock_balance(stock_id, changed_number,
                                                   changed_cost)
                buy_handler.update_buy_state(review_id, BuyInfo.normal())

            elif answer == QMessageBox.No:
                buy_handler.update_buy_state(review_id, BuyInfo.rejected())
            db_transaction_util.commit()
            self._init_table()
        except Exception as e:
            db_transaction_util.rollback()
            logger.error(e)
            logger.error('traceback.format_exc():\n{}'.format(
                traceback.format_exc()))
    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_exception:
                logger.error(db_exception.__str__())
                logger.error('traceback.format_exc():\n{}'.format(
                    traceback.format_exc()))
                db_transaction_util.rollback()
                QtWidgets.QMessageBox.information(self.submit, "提示",
                                                  "服务项目更新失败,请重试")
Beispiel #7
0
    def do_add(self):
        succeeded_list = '成功录入的行数:\n'
        failed_dict = OrderedDict()
        for row_index in range(1, self.line_number + 1):
            # 如果没有这个对应的序号属性,则说明已经删除,继续处理下一条记录
            if not hasattr(self, 'seq_' + str(row_index)):
                print(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 = brand_and_model_service.get_brand_by_name(brand)

                model_id = brand_and_model_service.get_model_by_name(brand_id, model)

                supplier_id = supplier_service.get_supplier_by_name(supplier)

                stock_info = stock_service.get_stock_by_model(model_id)

                # 如果通过型号找到库存,则单位属性沿用库存中的单位,并更新库存总额和库存量
                if stock_info:
                    stock_id = stock_info[0]
                else:
                    # 新增库存信息
                    second_service = getattr(self, 'second_service_' + line_number)
                    second_service_id = int(second_service.currentData())
                    stock_info = stock_service.add_stock_info(model, brand, model_id, brand_id, unit, second_service_id)
                    stock_id = stock_info.id()

                stock_service.update_stock_info(stock_id, number, total)

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

                change_type = StockDetail.by_bought()
                # 如果是退货,更新原来的进货信息中剩余量
                if number < 0:
                    buy_service.decrease_buy_left(stock_id, number)
                    buy_service.update_buy_unpaid(stock_id, total, supplier_id, payment)
                    change_type = StockDetail.by_returned()
                # 新增库存明细
                stock_service.add_stock_detail(stock_id, buy_id, total, number, change_type)

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

                db_transaction_util.commit()
                succeeded_list = succeeded_list + '第' + line_number + '行、'
                self.do_remove(line_number)
            except Exception as e:
                logger.error(e.__str__())
                logger.error('traceback.format_exc():\n{}'.format(traceback.format_exc()))
                failed_dict[line_number] = e.__str__()
                db_transaction_util.rollback()

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

        succeeded_list += '\n' + failed_info
        QMessageBox.information(self.submit, '提示', succeeded_list)
Beispiel #8
0
    def order(self, keyword, para_data):
        try:
            if self.request.method == 'POST':
                if keyword == "add":
                    today = datetime.now()

                    order_no = get_sale_order_no(today)

                    para_data["orderNo"] = order_no
                    para_data["createdTime"] = today
                    print(keyword)
                    try:
                        car_user = para_data.get("carUser")
                        user_id = para_data.get("userId")
                        worker_id = para_data.get("workerId")
                        pc_id = para_data.get("pcId")
                        car_phone = para_data.get("carPhone")
                        car_model = para_data.get("carModel")
                        car_id = para_data.get("carId")
                        pc_sign = para_data.get("pcSign")
                        worker_name = para_data.get("workerName")
                        order_check_id = get_uuid1()
                        save_data = {
                            'createdTime':
                            para_data.get("createdTime").strftime(
                                "%Y-%m-%d %H:%M:%S"),
                            'userId':
                            user_id,
                            'pcId':
                            pc_id,
                            'pcSign':
                            pc_sign,
                            'carId':
                            car_id,
                            'workerName':
                            worker_name,
                            'workerId':
                            worker_id,
                            'carUser':
                            car_user,
                            'carPhone':
                            car_phone,
                            'carModel':
                            car_model,
                            "orderNo":
                            order_no,
                            "orderCheckId":
                            order_check_id,
                            'code':
                            config.get_local_register_code(),
                        }

                        parameter = para_data.get("parameter", [])
                        if type(parameter) == str:
                            parameter = json.loads(parameter)

                        page = 0
                        for data in parameter:
                            page += 1
                            order_id = get_uuid1()

                            services = data.get('project')
                            services = services.split('-')
                            first_service_name = services[0]
                            second_service_name = services[1]

                            first_service_id = service_handler.get_service_id_by_name(
                                first_service_name)[0]
                            second_service_id = service_handler.get_service_id_by_name(
                                second_service_name, first_service_id)[0]

                            attributes = data.get('attribute')
                            logger.info(attributes)
                            try:
                                unit = attributes.get('单位', '')
                                unit_price = float(attributes.get('单价', ''))
                                number = int(attributes.get('数量', ''))
                                subtotal = float(attributes.get('小计', ''))
                                total = float(attributes.get('总价', ''))
                                note = attributes.get('备注', '')
                                model = attributes.get('型号', '')
                                brand = attributes.get('品牌', '')
                            except Exception as attribute_deal_error:
                                logger.error(attribute_deal_error)
                                unit = ''
                                unit_price = 0.0
                                number = 0
                                subtotal = 0.0
                                total = 0.0
                                note = ''
                                model = ''
                                brand = ''

                            temp = {
                                'project':
                                data.get('project'),
                                'id':
                                order_id,
                                'attribute':
                                json.dumps(attributes, ensure_ascii=False),
                                'serviceId':
                                second_service_id,
                                'unit':
                                unit,
                                'unit_price':
                                unit_price,
                                'number':
                                number,
                                'subtotal':
                                subtotal,
                                'total':
                                total,
                                'note':
                                note
                            }
                            db_transaction_util.begin()
                            logger.info('增加销售数据')
                            logger.info(temp.__str__())
                            logger.info(save_data.__str__())
                            sale_id = sale_handler.add_sale_info(
                                dict(temp, **save_data))

                            service_attributes = service_handler.get_attribute_by_service(
                                second_service_id)
                            all_required_attr = attribute_handler.get_all_required_attributes(
                            )
                            required_attr_list = []
                            for attr in all_required_attr:
                                required_attr_list.append(attr[1])

                            logger.info('增加销售扩展属性')
                            for srv_attr in service_attributes:
                                attr_name = srv_attr[1]
                                if attr_name not in required_attr_list:
                                    attr_id = attribute_handler.get_attr_by_name(
                                        attr_name)[0]
                                    sale_item_handler.add_sale_item(
                                        sale_id, attr_id,
                                        attributes.get(attr_name, ''))

                            # 库存信息更新
                            logger.info('更新库存信息')
                            stock_service.refresh_stock_info(
                                sale_id, brand, model, number, unit,
                                second_service_id)

                            # 回访设置
                            if data.get("callbackTime"):
                                logger.info('增加回访信息')
                                customer_handler.add_return_visit_data(
                                    data.get("callbackTime"), car_phone,
                                    car_id, car_user, today)
                            db_transaction_util.commit()
                    except Exception as add_error:
                        logger.error(add_error)
                        logger.error('traceback.format_exc():\n{}'.format(
                            traceback.format_exc()))
                        db_transaction_util.rollback()
                        raise ApiException(ErrorCode.ParameterMiss)

                    try:
                        p = "defaultPrinter"  # 打印机名称
                        html, page_height = self.preview_html(para_data, True)
                        logger.info('\n' + html)
                        Printer.printing(p, html, page_height)
                    except:
                        pass

                    return set_return_dicts({"orderNo": order_no})

                elif keyword == 'preview':
                    html = self.preview_html(para_data)
                    logger.info('\n' + html)
                    return set_return_dicts(html)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

            elif self.request.method == "GET":

                if not self.storeId:
                    raise ApiException(ErrorCode.PCError)

                if keyword == "detail":

                    check_order_id = para_data.get("checkOrderId")
                    if not check_order_id:
                        raise ApiException(ErrorCode.ParameterMiss)

                    if self.connect:
                        result_dict = SocketServer("orderdetail {} {}".format(
                            self.storeId, check_order_id))

                    else:
                        result = get_sale_info_by_one_key(
                            "orderCheckId", check_order_id)
                        result_list = list()

                        result_dict = {}
                        if result:
                            created_time = ''
                            car_id = ''
                            car_user = ''
                            car_phone = ''
                            car_model = ''
                            total_price = 0
                            order_no = ''
                            for data in result:
                                attribute = OrderedDict()
                                for attr in sale_item_handler.get_item_info_buy_sale_id(
                                        data['sale_id']):
                                    attribute[
                                        attr['name']] = attr['attribute_value']
                                logger.info('销售数据属性调整后的记录:' +
                                            attribute.__str__())
                                created_time = data['createdTime']
                                car_id = data['carId']
                                car_user = data['carUser']
                                car_phone = data['carPhone']
                                car_model = data['carModel']
                                price = data['unit_price']
                                pc_id = data['pcId']
                                order_no = data['orderNo']
                                if pc_id:
                                    total_price += price
                                    attribute['project'] = data['project']
                                    attribute['totalPrice'] = price
                                    attribute['orderNo'] = order_no
                                    result_list.append(attribute)

                            try:
                                pc_sign = config.get_store_name()
                            except:
                                pc_sign = ""
                            result_dict = {
                                "msg": result_list,
                                "totalPrice": total_price,
                                "createdTime": created_time,
                                "carId": car_id,
                                "carUser": car_user,
                                "carPhone": car_phone,
                                "carModel": car_model,
                                "orderNo": order_no,
                                "checkOrderId": check_order_id,
                                "pcSign": pc_sign,
                            }

                    if result_dict == 'restart':
                        raise ApiException(ErrorCode.ReStartPC)
                    return set_return_dicts(result_dict)
                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])
Beispiel #9
0
    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')

        # 计算剩余量
        if self.balance < 0:
            left_number = buy_number + self.balance
        else:
            left_number = buy_number

        try:
            db_transaction_util.begin()

            # 更新库存中的商品信息
            brand_id = brand_and_model_service.get_brand_by_name(brand_name)
            model_id = brand_and_model_service.get_model_by_name(
                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)

            # 更新库存
            stock_service.update_stock_info(self.stock_id, left_number,
                                            Decimal(left_number) * price)

            # 新增进货信息
            supplier_id = supplier_service.get_supplier_by_name(
                self.supplier.text())

            buy_id = buy_service.add_buy_info(self.stock_id, supplier_id,
                                              price, buy_number, buy_date,
                                              unpaid, paid, total, payment,
                                              note, left_number)

            # 新增进货库存明细
            stock_service.add_stock_detail(self.stock_id, buy_id, total,
                                           buy_number, StockDetail.by_bought())

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

            # 更新供应商付款信息
            supplier_service.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:
            logger.error(e.__str__())
            logger.error('traceback.format_exc():\n{}'.format(
                traceback.format_exc()))
            db_transaction_util.rollback()
            QMessageBox.information(self.writeOffButton, "提示",
                                    '销负失败,请重试!\n' + e.__str__())