当我有不同的型号时如何过滤

时间:2017-11-27 14:37:51

标签: odoo

这是.py:

func (r Render) Init() Render {
    globalPartials := r.getGlobalPartials()

    layout := r.TemplatesDir + r.Layout + r.Ext

    // Match multiple levels of templates
    viewDirs, _ := filepath.Glob(r.TemplatesDir + "**" + string(os.PathSeparator) + "*" + r.Ext)
    // Added the following two lines to match for app/views/some_file.html as well as files on the **/*.html matching pattern
    tmp, _ := filepath.Glob(r.TemplatesDir + "*" + r.Ext)
    viewDirs = append(viewDirs, tmp...)
    // Can be extended by replicating those two lines above and adding search paths within the base template path.

    fullPartialDir := filepath.Join(r.TemplatesDir + r.PartialDir)
    for _, view := range viewDirs {
        templateFileName := filepath.Base(view)
        //skip partials
        if strings.Index(templateFileName, "_") != 0 && strings.Index(view, fullPartialDir) != 0 {
            localPartials := r.findPartials(filepath.Dir(view))

            renderName := r.getRenderName(view)
            if r.Debug {
                log.Printf("[GIN-debug] %-6s %-25s --> %s\n", "LOAD", view, renderName)
            }
            allFiles := []string{layout, view}
            allFiles = append(allFiles, globalPartials...)
            allFiles = append(allFiles, localPartials...)
            r.AddFromFiles(renderName, allFiles...)
        }
    }

    return r
}

如何过滤ouvrage,当我更改附件模型的contrat_id时,我得到了所有  ouvrage模型相同contrat_id的模型ouvrage。

如果Attachement.contrat_id == Ouvrage.contrat_id则travSup_ids.ouvrage_id = Ouvrage.id

1 个答案:

答案 0 :(得分:0)

您可以在表单视图中指定这样的域:

<!-- this field must appear in the form so we can use it in domain -->
<field name="contrat_id"/>

<field name="travSup_ids">
    <tree....>
        <field name="ouvrage_id" domain="[('contrat_id', '=', parent.contrat_id)]/>

    </tree>
    <form>
        ....
        ....
        <field name="ouvrage_id" domain="[('contrat_id', '=', parent.contrat_id)]/>
    </form>
</field>

在嵌入的表单或树中,您可以访问当前表单的字段 使用parent.field_name