Example #1
0
def get_all_calibration():
    sql_text = '''
                SELECT
                       bi.id,
                       si.id as stock_id,
                       bi.buy_date,
                       BRAND_NAME,
                       MODEL_NAME,
                       di.value_desc,
                       si.balance,
                       bi.number,
                       si.total_cost,
                       bi.total,
                       ad.userName,
                       bi.note,
                       dic.value_desc
                  FROM stock_info si,buy_info bi, Admin ad, stock_detail sd, dictionary di, dictionary dic
                  WHERE si.id=bi.stock_id
                    AND bi.buy_type= {}
                    AND si.create_op = ad.id
                    AND sd.changed_id = bi.id
                    AND sd.stock_id = si.id
                    AND sd.type in ({},{})
                    AND dic.key_id = bi.state
                    AND dic.group_name = 'buy_state'
                    AND di.key_id = sd.type
                    AND di.group_name = 'stock_type\'''' \
        .format(BuyInfo.calibrated(), StockDetail.by_decreased(), StockDetail.by_increased())
    result = execute(sql_text)
    return result
Example #2
0
def add_buy_info(stock_id,
                 supplier_id,
                 price,
                 number,
                 buy_date,
                 unpaid,
                 paid,
                 total,
                 payment,
                 note,
                 left_number,
                 op=None,
                 buy_type=None,
                 state=0):
    buy_info = BuyInfo()
    buy_info.buy_date(buy_date)
    buy_info.stock_id(stock_id)
    buy_info.supplier_id(supplier_id)
    buy_info.unit_price(price)
    buy_info.payment_method(payment)

    if buy_type == BuyInfo.calibrated():
        buy_info.number(number)
        buy_info.total(total)
    else:
        buy_info.number(abs(number))
        buy_info.total(abs(total))

    create_time = time_utils.get_now()
    buy_info.create_time(create_time)
    if not op:
        create_op = common.config.login_user_info[0]
    else:
        create_op = op
    buy_info.create_op(create_op)

    buy_info.paid(abs(paid))
    buy_info.unpaid(abs(unpaid))

    buy_info.note(note)
    # 判断是进货还是退货
    if not buy_type:
        if number < 0:
            buy_info.buy_type(BuyInfo.returned())
            left_number = 0
        else:
            buy_info.buy_type(BuyInfo.bought())
    else:
        buy_info.buy_type(buy_type)

    if state:
        buy_info.state(state)

    buy_info.left(left_number)

    return buy_handler.add_buy_info(buy_info)
Example #3
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()))