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)
def add_buy_info(buy_info: BuyInfo) -> int: sql_text = ''' INSERT INTO buy_info( STOCK_ID, SUPPLIER_ID, UNIT_PRICE, NUMBER, BUY_DATE, CREATE_TIME, CREATE_OP, UNPAID, PAID, TOTAL, BUY_TYPE, note, left_number, state ) VALUES ( {}, {}, {:.2f}, {}, '{}', '{}', {}, {:.2f}, {:.2f}, {:.2f}, {}, '{}', {}, {} )''' \ .format(buy_info.stock_id(), buy_info.supplier_id(), buy_info.unit_price(), buy_info.number(), buy_info.buy_date(), buy_info.create_time(), buy_info.create_op(), buy_info.unpaid(), buy_info.paid(), buy_info.total(), buy_info.buy_type(), buy_info.note(), buy_info.left(), buy_info.state()) new_buy_id = execute(sql_text) return new_buy_id