场景背景:某门店预算项目,已有各品类的单价数据,各个门店各品类的销售折扣,销量数据。计算各门店各品类的销售金额,并计算各门店平均折扣和各品类的平均折扣。
财务模型搭建如下:

脚本触发时机为单价维护表保存后触发,拷贝范围是当前表单pov范围的year,所有category的单价。

脚本如下:
from deepcube.cube.cube import deepcube
from deepcube.cube import function as fn
def main(p1, p2):
    # 获取表单传参的year,赋值到变量中
    cur_year = p2['year']
    
    # 实例一个deepcube对象,传参为cube元素名和path,如果cube元素名在应用中唯一,可以不传path
    cube1 = deepcube('cube1', path='/deepcubeCase/cube')
    # 为了后续计算写法简单,在这里将cube的维度赋值给同名变量(注意这里cube1.year中的year是字段名)
    year = cube1.year
    period = cube1.period
    scenario = cube1.scenario
    version = cube1.version
    account = cube1.account
    category = cube1.category
    entity = cube1.entity
    
    # 从cube加载数据,需要指定取数的范围。
    cube1.init_data([year[cur_year],
                scenario["Actual"],
                version["Working"],
                account["UnitPrice"],
                category['Total'].Base()])
    
    # 确定一个背景scope范围
    cube1.scope(year[cur_year],
                scenario["Actual"],
                version["Working"],
                account["UnitPrice"]
                )
    # 计算
    cube1.loc[period["TotalPeriod"].Base(), entity['Total'].Base()] = cube1.loc[period["Beginning"], entity['NoEntity']]
    # 将计算结果写入Cube
    cube1.submit_calc()
回到顶部
咨询热线
