"""资产质量构造实验;金额为万元,Decimal全精度计算,展示时四舍五入到两位。 仅演示给定证据、已划定资产组及成本口径,不替代证据评价。 无参数执行写入本文件相邻JSON;改动INPUTS可复算其他构造情景。 """ from decimal import Decimal, ROUND_HALF_UP from pathlib import Path import json D = Decimal ZERO = D(0) def money(x): return format(D(x).quantize(D('0.01'), rounding=ROUND_HALF_UP), '.2f') def table(headers, rows): return {'headers': headers, 'rows': [[money(x) if isinstance(x, Decimal) else x for x in r] for r in rows]} def allocate(values, floors, loss): """商誉抵减后的有下限比例分摊;保留未分配值,绝不强塞突破下限。""" left = D(loss) allocated = [ZERO for _ in values] rounds = [] while left > D('1e-24'): active = [i for i, v in enumerate(values) if v - allocated[i] > floors[i]] if not active: break weight = sum(values[i] for i in active) proposals = [left * values[i] / weight if i in active else ZERO for i in range(len(values))] accepted = [min(proposals[i], values[i] - floors[i] - allocated[i]) for i in range(len(values))] rounds.append({'proposed': [money(x) for x in proposals], 'accepted': [money(x) for x in accepted]}) for i in active: allocated[i] += accepted[i] left -= sum(accepted) return allocated, rounds, left INPUTS = { 'DJ4-034': {'cost': 1200, 'depreciation': 400, 'fair_value': 740, 'disposal': 30, 'flows': [300, 280, 260], 'terminal': 40, 'rate': '0.10', 'alternative_fair_value': 850, 'mismatched_cash_factor': '0.75'}, 'DJ4-035': {'goodwill': 100, 'assets': [600, 300, 100], 'floors': [550, 0, 0], 'recoverable': 800, 'alternative_floors': [480, 0, 0], 'extreme_recoverable': 500}, 'DJ4-036': {'assets': [600, 400], 'goodwill': 200, 'operating_recoverable': 900, 'combined_recoverable': 950, 'alternative_operating_recoverable': 1000}, 'DJ4-037': {'quantity': 100, 'unit_cost': 10, 'contract_quantity': 60, 'contract_price': 13, 'market_price': 9, 'completion': 1, 'selling_tax': 1, 'alternative_contract_quantity': 80}, 'DJ4-038': {'batches': [{'name': '甲批', 'quantity': 100, 'unit_cost': 10, 'opening_allowance': 200, 'sold': 40, 'closing_unit_nrv': 9}, {'name': '乙批', 'quantity': 50, 'unit_cost': 8, 'opening_allowance': 0, 'sold': 0, 'closing_unit_nrv': 6}], 'alternative_unit_nrv': 12}, 'DJ4-039': {'cost': 1200, 'accumulated_depreciation': 360, 'recoverable': 600, 'residual': 60, 'remaining_years': 6, 'next_year_recoverable': 700}, 'DJ4-040': {'research': [20, 30, 40], 'development': [50, 60, 70, 80, 90, 100], 'condition_dates': ['2025-06-30', '2025-04-01', '2025-05-15', '2025-07-01', '2025-04-01'], 'ready': '2025-10-01', 'life_months': 60, 'amort_months': 3, 'alternative_resource_date': '2025-08-01'}, 'DJ4-041': {'ready': '2025-06-30', 'settled': '2025-12-31', 'estimate': 1200, 'actual': 1320, 'life_months': 120, 'residual': 0, 'old_months': 6, 'future_months_shown': 6}, 'DJ4-042': {'cost': 1000, 'original_residual': 100, 'original_life': 10, 'elapsed': 4, 'new_residual': 40, 'new_remaining_life': 8, 'sensitivity_residuals': [40, 100], 'sensitivity_lives': [6, 8]}, 'DJ4-043': {'host_cost': 800, 'host_life': 10, 'old_component_cost': 200, 'old_component_life': 5, 'elapsed_years': 3, 'new_component_cost': 300, 'new_component_life': 6, 'repair': 20}, 'DJ4-044': {'cost': 600, 'annual_recoverables': [650, 540], 'annual_years': [2023, 2024], 'change_date': '2025-01-01', 'finite_life': 6, 'residual': 0, 'alternative_life': 3, 'evidence': [['2023-01-01','外购可供使用,无明确终止期,不能预见利益期限','不确定'], ['2023-12-31','复核没有形成可预见期限,年度测试','不确定'], ['2024-12-31','复核寿命仍不确定,回收估计下滑','不确定'], ['2025-01-01','新技术替代安排成立,剩余利益期限六年','有限六年']]}, } def build(inputs=None): source = INPUTS if inputs is None else inputs out = {} x = source['DJ4-034']; carrying = D(x['cost']) - D(x['depreciation']) pvrows = [] for i, flow in enumerate(x['flows'], 1): end = D(x['terminal']) if i == len(x['flows']) else ZERO total = D(flow) + end factor = (1 + D(x['rate'])) ** i pvrows.append([i, D(flow), end, total, total / factor]) pv = sum(r[-1] for r in pvrows); net = D(x['fair_value']) - D(x['disposal']) alternative = D(x['alternative_fair_value']) - D(x['disposal']) mixedpv = pv * D(x['mismatched_cash_factor']) out['DJ4-034'] = {'inputs': x, 'tables': { 'present_values': table(['年末', '税前使用净现金', '终结净现金', '合计现金', '现值'], pvrows), 'comparison': table(['情景', '账面', '处置净额', '使用现值', '可收回金额', '减值'], [['基准', carrying, net, pv, max(net,pv), max(ZERO,carrying-max(net,pv))], ['仅处置报价提高', carrying, alternative, pv, max(alternative,pv), max(ZERO,carrying-max(alternative,pv))], ['错误现金乘七五折仍用税前率', carrying, net, mixedpv, max(net,mixedpv), max(ZERO,carrying-max(net,mixedpv))]])}} x = source['DJ4-035']; values = list(map(D,x['assets'])); floors = list(map(D,x['floors'])); gw = D(x['goodwill']) total = sum(values)+gw; loss = max(ZERO,total-D(x['recoverable'])); gwloss = min(loss,gw) alloc, rounds, pending = allocate(values,floors,loss-gwloss) alt, _, _ = allocate(values,list(map(D,x['alternative_floors'])),loss-gwloss) extreme = max(ZERO,total-D(x['extreme_recoverable'])) _, _, unallocated = allocate(values,floors,max(ZERO,extreme-gw)) rows = [['商誉', gw, ZERO, gw, gwloss, ZERO, gwloss, gw-gwloss]] for i,v in enumerate(values): rows.append([chr(65+i),v,floors[i],v-floors[i],D(rounds[0]['accepted'][i]),D(rounds[1]['accepted'][i]) if len(rounds)>1 else ZERO,alloc[i],v-alloc[i]]) out['DJ4-035']={'inputs':x,'rounds':rounds,'tables':{'allocation':table(['项目','原账面','下限','最大可减','首轮实配','次轮实配','总损失','末账面'],rows),'controls':table(['情景','总损失','商誉损失','A损失','B损失','C损失','未分配'],[['基准',loss,gwloss,*alloc,pending],['A下限改480',loss,gwloss,*alt,ZERO],['可收回额改500',extreme,min(extreme,gw),*allocate(values,floors,extreme-min(extreme,gw))[0],unallocated]])},'checks':{'loss_conserved':sum(alloc)+gwloss+pending==loss,'floors_respected':all(v-a>=f for v,a,f in zip(values,alloc,floors))}} x=source['DJ4-036']; values=list(map(D,x['assets'])); total=sum(values); gw=D(x['goodwill']); first=max(ZERO,total-D(x['operating_recoverable'])) firstalloc=[first*v/total for v in values]; second=max(ZERO,total-first+gw-D(x['combined_recoverable'])); correctgw=min(gw,second) wrongtotal=max(ZERO,total+gw-D(x['combined_recoverable'])); wronggw=min(gw,wrongtotal); wrongop=wrongtotal-wronggw altfirst=max(ZERO,total-D(x['alternative_operating_recoverable'])); altsecond=max(ZERO,total-altfirst+gw-D(x['combined_recoverable'])) out['DJ4-036']={'inputs':x,'tables':{'stages':table(['测试','比较账面','可收回额','本步减值','下一步经营资产','下一步商誉'],[['不含商誉',total,D(x['operating_recoverable']),first,total-first,gw],['再含商誉',total-first+gw,D(x['combined_recoverable']),second,total-first-(second-correctgw),gw-correctgw]]),'destination':table(['顺序','A损失','B损失','商誉损失','A期末','B期末','商誉期末','总损失'],[['正确',*firstalloc,correctgw,*[v-a for v,a in zip(values,firstalloc)],gw-correctgw,first+second],['错误先全抵商誉',*[wrongop*v/total for v in values],wronggw,*[v-wrongop*v/total for v in values],gw-wronggw,wrongtotal]]),'alternative':table(['改变条件','经营损失','第二步损失','商誉末值'],[['经营可收回额改1000',altfirst,altsecond,gw-min(gw,altsecond)]])}} x=source['DJ4-037']; q=x['quantity']; cost=D(x['unit_cost']); unitexpense=D(x['completion'])+D(x['selling_tax']) def layers(cq): rows=[] for name,n,p in [('合同内',min(q,cq),x['contract_price']),('超量',max(0,q-cq),x['market_price'])]: c=D(n)*cost; nrv=D(n)*(D(p)-unitexpense); loss=max(ZERO,c-nrv) rows.append([name,n,c,D(n)*D(p),D(n)*D(x['completion']),D(n)*D(x['selling_tax']),nrv,loss,c-loss]) return rows layers1=layers(x['contract_quantity']); layers2=layers(x['alternative_contract_quantity']); lc=sum(r[-2] for r in layers1); wrong=max(ZERO,sum(r[2] for r in layers1)-sum(r[-3] for r in layers1)) out['DJ4-037']={'inputs':x,'tables':{'layers':table(['层次','数量','成本','售价总额','完工费用','销售及税费','NRV','准备','净额'],layers1),'comparison':table(['算法或条件','准备','净额','相对基准准备减少'],[['分层计量',lc,D(q)*cost-lc,ZERO],['错误总额抵销',wrong,D(q)*cost-wrong,lc-wrong],['合同量改80',sum(r[-2] for r in layers2),sum(r[-1] for r in layers2),lc-sum(r[-2] for r in layers2)]]),'alternative_layers':table(['层次','数量','成本','售价总额','完工费用','销售及税费','NRV','准备','净额'],layers2)}} x=source['DJ4-038']; inventory=[]; roll=[] for b in x['batches']: q=b['quantity']; sold=b['sold']; remain=q-sold; c=D(b['unit_cost']); opening=D(b['opening_allowance']); used=opening*D(sold)/D(q); before=opening-used need=max(ZERO,(c-D(b['closing_unit_nrv']))*remain); provision=max(ZERO,need-before); reversal=max(ZERO,before-need) inventory.append([b['name'],q,sold,remain,c*remain,D(b['closing_unit_nrv'])*remain,need,c*remain-need]) roll.append([b['name'],opening,used,before,provision,reversal,need,D(sold)*c,D(sold)*c-used]) op=sum(r[1] for r in roll); used=sum(r[2] for r in roll); added=sum(r[4] for r in roll); rev=sum(r[5] for r in roll); close=sum(r[6] for r in roll) a=x['batches'][0]; remaining=a['quantity']-a['sold']; before=D(a['opening_allowance'])*(D(remaining)/D(a['quantity'])); need=max(ZERO,(D(a['unit_cost'])-D(x['alternative_unit_nrv']))*remaining) out['DJ4-038']={'inputs':x,'tables':{'inventory':table(['批次','期初量','卖出量','期末量','剩余成本','期末NRV','所需准备','净额'],inventory),'allowance':table(['批次','期初准备','随售转销','转销后准备','新计提','恢复转回','期末准备','售出原成本','结转净成本'],roll),'summary':table(['项目','金额'],[['期初准备',op],['加计提',added],['减转回',rev],['减转销',used],['期末准备',close],['本期减值费用净额',added-rev],['已售净成本',sum(r[-1] for r in roll)],['甲批NRV单价改12可转回',before-need],['甲批改12期末准备',need]])},'checks':{'rolls':op+added-rev-used==close}} x=source['DJ4-039']; carrying=D(x['cost'])-D(x['accumulated_depreciation']); loss=max(ZERO,carrying-D(x['recoverable'])); base=carrying-loss; residual=D(x['residual']); dep=(base-residual)/D(x['remaining_years']); olddep=(carrying-residual)/D(x['remaining_years']); running=base; schedule=[] for year in range(1,x['remaining_years']+1): end=running-dep; schedule.append([2025+year,running,dep,end]);running=end nextbase=base-dep; false_rev=max(ZERO,D(x['next_year_recoverable'])-nextbase) out['DJ4-039']={'inputs':x,'tables':{'bridge':table(['原成本','累计折旧','测试前账面','可收回额','本期减值','测试后账面','原年折旧','新年折旧'],[[D(x['cost']),D(x['accumulated_depreciation']),carrying,D(x['recoverable']),loss,base,olddep,dep]]),'schedule':table(['年度','期初净值','当年折旧','期末净值'],schedule),'recovery':table(['处理','次年末账面','当年转回收益','以后每年折旧'],[['正确不转回',nextbase,ZERO,dep],['错误按700恢复',nextbase+false_rev,false_rev,(nextbase+false_rev-residual)/D(x['remaining_years']-1)]])}} x=source['DJ4-040']; cutoff=max(x['condition_dates']); allflows=[]; capital=ZERO; expense=ZERO for month,amount in enumerate(x['research']+x['development'],1): date=f'2025-{month:02d}-01'; kind='研究费用' if month<=len(x['research']) else ('开发资本化' if date>=cutoff and date=altcutoff and f'2025-{i:02d}-01'