odoo如何在网站模板中设置所选属性

时间:2015-10-13 09:24:47

标签: forms select odoo

我在Odoo中遇到了一些麻烦,为网站公式设置了所选属性。

我在底层模型中有一些数据,它显示在表单内的表格中。线条显示正确,但未正确设置选择字段的值。它始终显示选择列表中的第一个值,而不是模型中保存的值。

    <t t-foreach="quote_lines" t-as="quote_line">               
    <tr>
       <td>
          <!--  public categories for a selection field -->
          <select t-attf-name="supplier_{{quote_line.line}}">
             <t t-foreach="categories" t-as="c">
                <t t-if="c.name==quote_line.supplier"><option t-field="c.name" selected="selected" /></t>
                <t t-if="c.name!=quote_line.supplier"><option t-field="c.name" /></t>
             </t>
          </select>
        </td>
        ....
    </tr>
    </t>

表单加载到odoo并显示正常 - 除了-tag忽略我选择的属性。当我查看生成的html时,会设置select / option值,只会忽略此属性。

任何提示我做错了什么或者只是看不到?

1 个答案:

答案 0 :(得分:2)

尝试使用selected="True"

另外,请看一下 website_sale 对各国的影响:

              <div t-attf-class="form-group #{error.get('shipping_country_id') and 'has-error' or ''} col-lg-6">
                  <label class="control-label" for="shipping_country_id">Country</label>
                  <select name="shipping_country_id" class="form-control" t-att-disabled="  'disabled' if shipping_id &gt;= 0 else ''">
                      <option value="">Country...</option>
                      <t t-foreach="countries or []" t-as="country">
                          <option t-att-value="country.id" t-att-selected="country.id == checkout.get('shipping_country_id')"><t t-esc="country.name"/></option>
                      </t>
                  </select>
              </div>

https://github.com/odoo/odoo/blob/9.0/addons/website_sale/views/templates.xml#L1072-L1080