Как определить причину ValueError: элемент не может быть расположен в родительском представлении? - Odoo 10.0e Enterprise

Недавно я совершил ошибку, обновив базовый модуль, пытаясь настроить отчеты путем наследования через настраиваемый модуль. Я работаю над настройками, которые были выполнены в режиме разработчика в пользовательском интерфейсе. Мне удалось исправить предыдущие настройки, которые хранились в ir_ui_view. Однако я получаю сообщение об ошибке при попытке распечатать счета в формате PDF, и мне не удалось найти причину. Есть некоторая связь, которую я еще не нашел, и я использую ее как возможность понять наследование отчетов.

Ошибка:

ValueError: Element '<xpath expr="//div/[@name='invoice_address']">' cannot be located in parent view

Error context:
View `report_invoice_document_inherit_sale`
[view_id: 1119, xml_id: sale.report_invoice_document_inherit_sale, model: n/a, parent_id: 735]

load could not load template
Template: account.report_invoice_document

Вот наследство от ir_ui_view:

<?xml version="1.0"?>
<data inherit_id="account.report_invoice_document">
        <xpath expr="//div[@name='invoice_address']" position="attributes">
            <attribute name="groups">!sale.group_delivery_invoice_address</attribute>
        </xpath>
        <xpath expr="//div[@name='invoice_address']" position="before">
            <div class="col-xs-5 col-xs-offset-7" groups="sale.group_delivery_invoice_address">
                <strong t-if="o.partner_shipping_id == o.partner_id">Invoicing and shipping address:</strong>
                <strong t-if="o.partner_shipping_id != o.partner_id">Invoicing address:</strong>
                <div t-field="o.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
                 <span t-if="o.partner_id.vat">TIN: <span t-field="o.partner_id.vat"/></span>
                <div t-if="o.partner_shipping_id != o.partner_id" class="mt8">
                    <strong>Shipping address:</strong>
                    <div t-field="o.partner_shipping_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;], &quot;no_marker&quot;: True}"/>
                    <span t-if="o.partner_id.vat">TIN: <span t-field="o.partner_id.vat"/></span>
                </div>
            </div>
        </xpath>
   </data>

А вот и родительский файл account\reports\report_invoice.xml, содержащий шаблон 'report_invoice_document':

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_invoice_document">
    <t t-call="report.external_layout">
        <t t-set="o" t-value="o.with_context({'lang':o.partner_id.lang})" />
        <div class="page">
            <div class="row">
                <div name="invoice_address" class="col-xs-5 col-xs-offset-7">
                    <address t-field="o.partner_id"
                    t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
                    <span t-if="o.partner_id.vat">TIN: <span t-field="o.partner_id.vat"/></span>
                </div>
            </div>

            <h2>
                <span t-if="o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')">Invoice</span>
                <span t-if="o.type == 'out_invoice' and o.state == 'proforma2'">PRO-FORMA</span>
                <span t-if="o.type == 'out_invoice' and o.state == 'draft'">Draft Invoice</span>
                <span t-if="o.type == 'out_invoice' and o.state == 'cancel'">Cancelled Invoice</span>
                <span t-if="o.type == 'out_refund'">Refund</span>
                <span t-if="o.type == 'in_refund'">Vendor Refund</span>
                <span t-if="o.type == 'in_invoice'">Vendor Bill</span>
                <span t-field="o.number"/>
            </h2>

            <div class="row mt32 mb32">
                <div class="col-xs-2" t-if="o.name">
                    <strong>Description:</strong>
                    <p t-field="o.name"/>
                </div>
                <div class="col-xs-2" t-if="o.date_invoice">
                    <strong>Invoice Date:</strong>
                    <p t-field="o.date_invoice"/>
                </div>
                <div class="col-xs-2" t-if="o.date_due and o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')">
                    <strong>Due Date:</strong>
                    <p t-field="o.date_due"/>
                </div>
                <div class="col-xs-2" t-if="o.origin">
                    <strong>Source:</strong>
                    <p t-field="o.origin"/>
                </div>
                <div class="col-xs-2" t-if="o.partner_id.ref">
                    <strong>Customer Code:</strong>
                    <p t-field="o.partner_id.ref"/>
                </div>
                <div name="reference" class="col-xs-2" t-if="o.reference and o.type == 'in_invoice'">
                    <strong>Reference:</strong>
                    <p t-field="o.reference"/>
                </div>
            </div>

            <!-- Is there a discount on at least one line? -->
            <t t-set="display_discount" t-value="any([l.discount for l in o.invoice_line_ids])"/>

            <table class="table table-condensed">
                <thead>
                    <tr>
                        <th>Description</th>
                        <th class="hidden">Source Document</th>
                        <th class="text-right">Quantity</th>
                        <th class="text-right">Unit Price</th>
                        <th t-if="display_discount" class="text-right" groups="sale.group_discount_per_so_line">Disc.(%)</th>
                        <th class="text-right">Taxes</th>
                        <th class="text-right">Tax Excluded Price</th>
                    </tr>
                </thead>
                <tbody class="invoice_tbody">
                    <tr t-foreach="o.invoice_line_ids" t-as="l">
                        <td><span t-field="l.name"/></td>
                        <td class="hidden"><span t-field="l.origin"/></td>
                        <td class="text-right">
                            <span t-field="l.quantity"/>
                            <span t-field="l.uom_id"  groups="product.group_uom"/>
                        </td>
                        <td class="text-right">
                            <span t-field="l.price_unit"/>
                        </td>
                        <td t-if="display_discount" class="text-right" groups="sale.group_discount_per_so_line">
                            <span t-field="l.discount"/>
                        </td>
                        <td class="text-right">
                            <span t-esc="', '.join(map(lambda x: (x.description or x.name), l.invoice_line_tax_ids))"/>
                        </td>
                        <td class="text-right">
                            <span t-field="l.price_subtotal" 
                             t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                        </td>
                    </tr>
                </tbody>
            </table>



            <div class="row">
                <div class="col-xs-4 pull-right">
                    <table class="table table-condensed">
                        <tr class="border-black">
                            <td><strong>Subtotal</strong></td>
                            <td class="text-right">
                                <span t-field="o.amount_untaxed" options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                            </td>
                        </tr>
                        <t t-foreach="o._get_tax_amount_by_group()" t-as="amount_by_group">
                            <tr>
                                <td><span t-esc="amount_by_group[0]"/></td>
                                <td class="text-right">
                                    <span t-esc="amount_by_group[1]"/>
                                </td>
                            </tr>
                        </t>
                        <tr class="border-black">
                            <td><strong>Total</strong></td>
                            <td class="text-right">
                                 <span t-field="o.amount_total" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <p t-if="o.comment">
                <strong>Comment:</strong>
                <span t-field="o.comment"/>
            </p>
            <p t-if="o.payment_term_id">
                <span t-field="o.payment_term_id.note"/>
            </p>
            <p t-if="o.fiscal_position_id.note">
                <strong>Fiscal Position Remark:</strong>
                <span t-field="o.fiscal_position_id.note"/>
            </p>
         </div>
    </t>
</template>

<template id="report_invoice">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="account.report_invoice_document" t-lang="o.partner_id.lang"/>
       </t>
    </t>
</template>

<template id="account_invoice_report_duplicate" inherit_id="account.report_invoice_document" primary="True">
    <xpath expr="//h2" position="replace">
        <h2>
            <span>Duplicate</span>
            <span t-field="o.number"/>
        </h2>
    </xpath>
</template>

<template id="account_invoice_report_duplicate_main">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="account.account_invoice_report_duplicate" t-lang="o.partner_id.lang"/>
        </t>
    </t>
</template>
</data>
</odoo>

person AE Cook    schedule 28.02.2018    source источник
comment
Я понимаю, что мое первоначальное объяснение - тарабарщина. Раньше я выполнял все настройки представлений и отчетов через экран настроек в режиме разработчика. Я учусь разрабатывать собственные модули для расширения Odoo, чтобы мои изменения не потерялись при обновлении. В процессе этого я обновил базовый модуль, который удалил мои предыдущие настройки из ir_ui_view. Мне удалось обновить эту таблицу с использованием предыдущих значений, но я получаю указанную выше ошибку при печати счетов-фактур в PDF, и я думаю, что ошибка связана, но я не могу определить причину.   -  person AE Cook    schedule 28.02.2018
comment
Можете ли вы еще больше уменьшить это? Попробуйте найти воспроизводимый случай с наименьшим количеством кода.   -  person Litty    schedule 28.02.2018
comment
Проблема в том, что я думаю, что это неизмененный отчет о счете, поэтому я пытаюсь понять, почему он вызывает ошибку. Я бы не знал, с чего начать сокращать код, поскольку мне нужен отчет как есть.   -  person AE Cook    schedule 28.02.2018
comment
Возможность сократить код до минимального количества воспроизведений - это критически важный навык разработки, который очень помогает при задании необычных вопросов, подобных этому. Вам придется сделать несколько обоснованных предположений и встретиться здесь посередине, если только эксперт по odoo не придет и не знает, что происходит :)   -  person Litty    schedule 28.02.2018


Ответы (1)


Спасибо, Литти, за помощь. Я обнаружил, что обновил поле arch_db в ir_ui_view для идентификатора 735 (account.report_invoice_document) с неправильными значениями, поэтому зависимые документы пытались наследовать совершенно несвязанный XML.

Мне просто удалить вопрос?

person AE Cook    schedule 28.02.2018