fix: correct post-tax unit price calculation in buy inbound service
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -117,7 +117,13 @@ class BuyInboundService:
|
||||
|
||||
in_qty = float(data.get('in_quantity') or 0)
|
||||
u_price = float(data.get('unit_price') or 0)
|
||||
tax_rate = float(data.get('tax_rate') or 0) # [新增]
|
||||
tax_rate = float(data.get('tax_rate') or 0)
|
||||
|
||||
# 计算税后单价
|
||||
post_tax_price = float(data.get('post_tax_unit_price') or 0)
|
||||
if post_tax_price == 0 and u_price > 0:
|
||||
tax_multiplier = 1 + (tax_rate / 100)
|
||||
post_tax_price = u_price * tax_multiplier
|
||||
|
||||
try:
|
||||
seq_sql = text("SELECT nextval('global_print_seq')")
|
||||
@ -138,8 +144,8 @@ class BuyInboundService:
|
||||
|
||||
# 价格信息
|
||||
pre_tax_unit_price=u_price,
|
||||
post_tax_unit_price=float(data.get('post_tax_unit_price') or 0),
|
||||
tax_rate=tax_rate, # [新增]
|
||||
post_tax_unit_price=post_tax_price,
|
||||
tax_rate=tax_rate,
|
||||
total_price=in_qty * u_price,
|
||||
currency=data.get('currency', 'CNY'),
|
||||
exchange_rate=data.get('exchange_rate', 1.0),
|
||||
@ -183,10 +189,22 @@ class BuyInboundService:
|
||||
if 'arrival_photo' in data: stock.arrival_photo = json.dumps(data['arrival_photo'])
|
||||
if 'inspection_report' in data: stock.inspection_report = json.dumps(data['inspection_report'])
|
||||
|
||||
# [新增] 更新税率
|
||||
if 'tax_rate' in data: stock.tax_rate = float(data['tax_rate'])
|
||||
# 更新税率
|
||||
if 'tax_rate' in data:
|
||||
stock.tax_rate = float(data['tax_rate'])
|
||||
|
||||
# 更新税前单价
|
||||
if 'unit_price' in data:
|
||||
stock.pre_tax_unit_price = float(data['unit_price'])
|
||||
|
||||
# 更新税后单价
|
||||
if 'post_tax_unit_price' in data: stock.post_tax_unit_price = float(data['post_tax_unit_price'])
|
||||
if 'post_tax_unit_price' in data:
|
||||
stock.post_tax_unit_price = float(data['post_tax_unit_price'])
|
||||
else:
|
||||
# 如果税后单价没有提供,根据税前单价和税率计算
|
||||
if 'unit_price' in data or 'tax_rate' in data:
|
||||
tax_multiplier = 1 + (float(data.get('tax_rate', stock.tax_rate or 0)) / 100)
|
||||
stock.post_tax_unit_price = float(stock.pre_tax_unit_price) * tax_multiplier
|
||||
|
||||
if 'in_quantity' in data:
|
||||
diff = float(data['in_quantity']) - float(stock.in_quantity)
|
||||
@ -195,8 +213,7 @@ class BuyInboundService:
|
||||
stock.stock_quantity = float(stock.stock_quantity) + diff
|
||||
stock.available_quantity = float(stock.available_quantity) + diff
|
||||
|
||||
if 'unit_price' in data: stock.pre_tax_unit_price = float(data['unit_price'])
|
||||
|
||||
# 重新计算总价
|
||||
stock.total_price = float(stock.in_quantity) * float(stock.pre_tax_unit_price)
|
||||
db.session.commit()
|
||||
return stock
|
||||
|
||||
Reference in New Issue
Block a user