コード例 #1
0
 def _model_index_changed(self):
     model_id = self.model_combo.currentData()
     if not model_id:
         balance = 0
         cost = 0.0
         self.stock_id = 0
     else:
         model_id = int(model_id)
         stock_info = stock_handler.get_stock_by_model(model_id)
         balance = stock_info['balance']
         cost = stock_info['total_cost']
         self.stock_id = stock_info['id']
     self.original_balance = balance
     self.original_cost = cost
     self.balance_in_db.setText(str(balance))
     self.money_in_db.setText(str(cost))
コード例 #2
0
    def _submit(self):
        # stock = Stock()
        #
        # brand = self.brand_combo
        # stock.brand_name(brand.currentText()).brand_id(brand.currentData())
        #
        # model = self.model_combo
        # stock.model_name(model.currentText()).model_id(model.currentData())
        #
        # name = brand.currentText() + '-' + model.currentText()
        # stock.name(name)
        # # stock.unit(self.unit.text())
        # stock.create_op(self.staffComb.currentData())
        # stock.create_time(self.dateEdit.text())
        #
        # stock_id = stock_handler.add_stock_info(stock)
        model = self.model_combo
        stock_info = stock_handler.get_stock_by_model(model.currentData())
        buy_info = BuyInfo()
        buy_info.buy_date(self.dateEdit.text())
        buy_info.stock_id(stock_info[0])
        buy_info.supplier_id("99999")
        buy_info.unit_price(Decimal(self.money.text()))

        create_time = time_utils.get_now()
        buy_info.create_time(create_time)
        create_op = self.staffComb.currentData()
        buy_info.create_op(create_op)

        # buy_info.paid(abs(paid))
        # buy_info.unpaid(abs(unpaid))
        buy_info.total(Decimal(self.toal.text()))

        buy_info.note(self.notes.text())
        buy_info.buy_type("8")
        buy_handler.add_buy_info(buy_info)
        QMessageBox.information(self.addButton, '提示', '校准成功!')
        self.close()
コード例 #3
0
def get_stock_by_model(model_id: int):
    return stock_handler.get_stock_by_model(model_id)
コード例 #4
0
ファイル: service_handler.py プロジェクト: zgj0607/Py-store
    def ApiService(self, keyword, para_data):
        try:
            if self.request.method == "GET":
                if keyword == "one":
                    second_services = service_handler.get_all_first_level_service()
                    send_data = list()
                    for data in second_services:
                        send_data.append({
                            "oneMenuId": data[0],
                            "name": data[1]
                        })
                    return set_return_dicts(send_data)

                elif keyword == "two":
                    first_service_id = para_data.get("oneMenuId")
                    second_services = service_handler.get_second_service_by_father(first_service_id)
                    send_data = list()
                    for data in second_services:
                        second_service_id = data[2]
                        second_service_name = data[3]
                        attribute_dict = {}
                        for attr in service_handler.get_attribute_by_service(second_service_id):
                            attribute_dict[attr[1]] = '1'

                        send_data.append({
                            "twoMenuId": second_service_id,
                            "name": second_service_name,
                            "attribute": attribute_dict,
                        })
                    return set_return_dicts(send_data)

                elif keyword == 'brand':
                    second_service_id = para_data.get['second_service_id']
                    brands = []
                    for brand in stock_handler.get_brand_by_second_service(second_service_id):
                        brands.append({'name': brand['brand_name'], 'id': brand['brand_id']})
                    send_data = {
                        'second_service_id': second_service_id,
                        'brands': brands
                    }
                    return set_return_dicts(send_data)

                elif keyword == 'model':
                    second_service_id = para_data.get['second_service_id']
                    brand_id = para_data.get['brand_id']
                    models = []
                    for model in stock_handler.get_model_by_second_service_and_brand(second_service_id, brand_id):
                        models.append(({'name': model['model_name'], 'id': model['model_id']}))
                    send_data = {
                        'second_service_id': second_service_id,
                        'models': models
                    }
                    return set_return_dicts(send_data)

                elif keyword == 'balance':
                    model_id = para_data.get['model_id']
                    stock = stock_handler.get_stock_by_model(model_id)
                    if stock:
                        balance = stock['balance']
                    else:
                        balance = 0
                    send_data = {
                        'model_id': model_id,
                        'balance': balance
                    }

                    return set_return_dicts(send_data)

                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'])
コード例 #5
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)