当前位置: 首页>>代码示例>>Python>>正文


Python Template.make_module方法代码示例

本文整理汇总了Python中jinja2.Template.make_module方法的典型用法代码示例。如果您正苦于以下问题:Python Template.make_module方法的具体用法?Python Template.make_module怎么用?Python Template.make_module使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2.Template的用法示例。


在下文中一共展示了Template.make_module方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_deduction

# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import make_module [as 别名]
def make_deduction(doc_salary, doc_type, doc_struct, context, result_description, precision):

    tributavel_calcule = doc_type.tributavel_expression

    if not result_description.get("deductions"):
        result_description["deductions"] = []

    if not doc_struct.d_modified_amt:
        doc_struct.d_modified_amt = 0

    if not tributavel_calcule:
        tributavel_value = rounded(doc_struct.d_modified_amt, precision)
        res = {"idx": doc_struct.idx, "d_modified_amt": tributavel_value}
        result_description.get("deductions").append(res)
        return tributavel_value

    doc_type_dict = doc_type.as_dict()

    for attr in ("tributavel_calcule", "parent", "parenttype", "parentfield", "owner", "modified_by"):
        doc_type_dict.pop(attr, None)
        doc_struct.pop(attr, None)
        doc_salary.pop(attr, None)

        # context.update({doc_type_dict.short_name: doc_type_dict})
        # context.update({doc_struct.short_name: doc_struct})

    context.update(doc_struct)
    context.update(doc_type_dict)

    try:
        t = Template(tributavel_calcule, extensions=["jinja2.ext.do"], trim_blocks=True)
        set_functions_context(t)
        m = t.make_module(context)

        # try:
        # if (doc_type.deduction_type == "Table"):
        # 	print "table name %s date %s" % (doc_salary.earnings, doc_salary.from_date)
        # except:
        # 	print "there is no table_name %s" % frappe.utils.encode(doc_employee.estado_civil)

        try:
            value = m.tribut
        except AttributeError:
            value = 0

        if value:
            tributavel_value = rounded(value, precision)
        else:
            tributavel_value = rounded(0, precision)

        res = {"idx": doc_struct.idx, "d_modified_amt": tributavel_value}
        context[doc_type_dict.short_name] = res
        result_description.get("deductions").append(res)
        print "short_name %s res %s idx %s tributavel_value %s" % (
            doc_type_dict.short_name,
            context.get(doc_type_dict.short_name),
            doc_struct.idx,
            tributavel_value,
        )
        return tributavel_value
    except TaxDependencyError:
        pass
    except:
        d_type = frappe.utils.encode(doc_struct.d_type)
        frappe.throw(_("Error in rule for Earning Type {}. Please check jinja2 syntax.".format(d_type)))
开发者ID:saguas,项目名称:l10n_pt_hr_salary,代码行数:67,代码来源:calculate_tributavel.py

示例2: get_tributavel_value

# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import make_module [as 别名]
def get_tributavel_value(doc_salary, doc_type, doc_struct, precision):

    tributavel_calcule = doc_type.tributavel_calcule

    if not tributavel_calcule:
        tributavel_value = rounded(doc_struct.modified_value, precision)
        return tributavel_value

    is_diary = doc_type.diary_earning_

    if is_diary:
        value = doc_struct.modified_value_diary
    else:
        value = doc_struct.modified_value

    context = {"value": value}

    doc_employee = frappe.get_doc("Employee", doc_salary.employee).as_dict()
    doc_type_dict = doc_type.as_dict()

    for attr in (
        "tributavel_calcule",
        "parent",
        "parenttype",
        "parentfield",
        "owner",
        "modified_by",
        "short_name",
        "idx",
    ):
        doc_type_dict.pop(attr, None)
        doc_struct.pop(attr, None)
        doc_employee.pop(attr, None)

    context.update({doc_type_dict.short_name: doc_type_dict})
    context.update({doc_struct.short_name: doc_struct})

    context.update(doc_employee)
    context.update(doc_struct)
    context.update(doc_type_dict)

    try:
        t = Template(tributavel_calcule, extensions=["jinja2.ext.do"], trim_blocks=True)
        set_functions_context(t)
        m = t.make_module(context)

        try:
            value = m.tribut
        except AttributeError:
            value = 0

        if value:
            tributavel_value = rounded(value, precision)
            if is_diary:
                tributavel_value = tributavel_value * 31
        else:
            tributavel_value = rounded(0, precision)

        return tributavel_value
    except:
        e_type = frappe.utils.encode(doc_struct.e_type)
        frappe.throw(_("Error in rule for Earning Type {}. Please check jinja2 syntax.".format(e_type)))
开发者ID:saguas,项目名称:l10n_pt_hr_salary,代码行数:64,代码来源:calculate_tributavel.py


注:本文中的jinja2.Template.make_module方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。