Odoo - Объединить два заголовка полей в один2много

Я работаю с odoo 10-e. Я создал собственный модуль, и в этом модуле я хочу показать такие записи one2many

----------------
| Long Cell    |
----------------
| 1    | 2     |
----------------

прямо сейчас по умолчанию каждый столбец имеет свой собственный заголовок, который на самом деле имеет значение string=. Я хочу переопределить поведение по умолчанию.


person Ancient    schedule 28.07.2017    source источник
comment
вам нужна функция, как в таблице html для colspan в списке odoo. Правильно ?   -  person Chavada Viki    schedule 29.07.2017


Ответы (1)


Сначала создайте файл xml, который расширяет шаблон ListView, чтобы добавить функцию colspan в базовый шаблон представления списка.

colspan.xml

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<div t-extend="ListView">
     <t t-jquery="table" t-operation="replace">
        <table class="o_list_view table table-condensed table-striped">
        <t t-set="columns_count" t-value="visible_columns.length + (options.selectable ? 1 : 0) + (options.deletable ? 1 : 0)"/>
        <thead>
            <tr t-if="options.header">
                <t t-foreach="columns" t-as="column">
                    <th t-if="column.meta">
                        <t t-esc="column.string"/>
                    </th>
                </t>
                <th t-if="options.selectable" class="o_list_record_selector" width="1">
                    <div class="o_checkbox">
                        <input type="checkbox"/><span/>
                    </div>
                </th>
                <t t-set="col" t-value="0"/>
                <t t-foreach="columns" t-as="column">
                    <t t-if="col == 0">
                    <th t-if="!column.meta and column.invisible !== '1'" t-att-data-id="column.id"
                        t-attf-class="text-center #{((options.sortable and column.sortable and column.tag !== 'button') ? 'o_column_sortable' : '')}"
                            t-att-width="column.width()" t-att-colspan="column.colspan" >
                        <t t-set="col" t-value="column.colspan or 1"/>    
                        <t t-if="column.tag !== 'button'"><t t-raw="column.heading()"/></t>
                    </th>
                    </t>
                    <t t-if="col !== 0" t-set="col" t-value="col - 1"/>
                </t>
                <th t-if="options.deletable" class="o_list_record_delete"/>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td t-if="options.selectable"/>
                <td t-foreach="aggregate_columns" t-as="column" t-att-data-field="column.id" t-att-title="column.label">
                </td>
                <td t-if="options.deletable" class="o_list_record_delete"/>
            </tr>
        </tfoot>
    </table>
    </t>
</div>
</template>

Добавить в __manifest__.py

...
'qweb': [
        "static/src/xml/colspan.xml",
    ],
...

Вот и все.

Вы можете использовать colspan в любом поле. в списке.

Eg.

<tree>
    <field name="any_field" colspan="2"/>
</tree>

Попробуй это.

Я надеюсь, что это сработает для вас.

person Chavada Viki    schedule 31.07.2017
comment
Я получил эту ошибку: odoo.tools.convert: The XML file does not fit the required schema - person Ancient; 31.07.2017
comment
На самом деле это была моя вина. Теперь он работает отлично. Большое спасибо - person Ancient; 31.07.2017
comment
Не могли бы вы помочь мне еще немного, просто дайте мне знать, где я могу найти вышеуказанные вещи в документации odoo. Я имею в виду, определяется ли это где-либо, как настраивать такие вещи - person Ancient; 31.07.2017
comment
Не, точно в документации. я только что взял ссылку из этой документации для наследования шаблона. - person Chavada Viki; 01.08.2017