def _add_buy_info(stock_id, supplier_id, price, number, buy_date, unpaid,
                      paid, total, payment, note, balance):
        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)

        buy_info.number(abs(number))

        create_time = time_utils.get_now()
        buy_info.create_time(create_time)
        create_op = Common.config.login_user_info[0]
        buy_info.create_op(create_op)

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

        buy_info.note(note)
        buy_info.buy_type(BuyInfo.bought())
        # 计算剩余量
        if balance < 0:
            left_number = number + balance
        else:
            left_number = number

        buy_info.left(left_number)

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