我正在尝试根据需要设置 invoice_payment_term_id 字段。通常只需添加 required="1" 就可以了,但在这里不行:
<!-- Invoice payment terms (only invoices) + due date (only invoices / receipts) -->
<label for="invoice_payment_term_id" attrs="{'invisible': [('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
<div class="d-flex" attrs="{'invisible': [('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}">
<field name="invoice_payment_term_id" placeholder="Terms" attrs="{'invisible': [('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
<span class="o_form_label mx-3 oe_edit_only" attrs="{'invisible': [ '|', '|', '|', ('state', '!=', 'draft'), ('invoice_payment_term_id', '!=', False), ('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"> or </span>
<field name="invoice_date_due" force_save="1" placeholder="Date" attrs="{'invisible': ['|', ('invoice_payment_term_id', '!=', False), ('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
</div>
我努力了:
<field name="invoice_payment_term_id" placeholder="Terms" required="1" attrs="{'invisible': [('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
和
<field name="invoice_payment_term_id" placeholder="Terms" attrs="{'invisible': [('type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))], 'required': [('type', 'not in', 'in_refund')]}"/>
顺便说一句,'not in'、'in_refund' 只是一个试图让它运行的修饰符,但可以是你喜欢的任何其他修饰符。
根据@Mayur Jotaniya,以下是整个代码:
<t t-name="account.report_invoice_document">
<t t-call="web.external_layout">
<t t-set="o" t-value="o.with_context(lang=lang)"/>
<t t-set="address">
<address t-field="o.partner_id" t-options="{"widget": "contact", "fields": ["address", "name"], "no_marker": True}"/>
<div t-if="o.partner_id.vat" class="mt16">
<t t-if="o.company_id.country_id.vat_label" t-esc="o.company_id.country_id.vat_label" id="inv_tax_id_label"/>
<t t-else="">Tax ID</t>: <span t-field="o.partner_id.vat"/></div>
</t>
<div class="page">
<h2>
<span t-if="o.type == 'out_invoice' and o.state == 'posted'">Invoice</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'">Credit Note</span>
<span t-if="o.type == 'in_refund'">Vendor Credit Note</span>
<span t-if="o.type == 'in_invoice'">Vendor Bill</span>
<span t-if="o.name != '/'" t-field="o.name"/>
</h2>
<div id="informations" class="row mt32 mb32">
<div class="col-auto mw-100 mb-2" t-if="o.invoice_date" name="invoice_date">
<strong>Invoice Date:</strong>
<p class="m-0" t-field="o.invoice_date"/>
</div>
<div class="col-auto mw-100 mb-2" t-if="o.invoice_date_due and o.type == 'out_invoice' and o.state == 'posted'" name="due_date">
<strong>Due Date:</strong>
<p class="m-0" t-field="o.invoice_date_due"/>
</div>
<div class="col-auto mw-100 mb-2" t-if="o.invoice_origin" name="origin">
<strong>Source:</strong>
<p class="m-0" t-field="o.invoice_origin"/>
</div>
<div class="col-auto mw-100 mb-2" t-if="o.partner_id.ref" name="customer_code">
<strong>Customer Code:</strong>
<p class="m-0" t-field="o.partner_id.ref"/>
</div>
<div class="col-auto mw-100 mb-2" t-if="o.ref" name="reference">
<strong>Reference:</strong>
<p class="m-0" t-field="o.ref"/>
</div>
</div>
<t t-set="display_discount" t-value="any([l.discount for l in o.invoice_line_ids])"/>
<table class="table table-sm o_main_table" name="invoice_line_table">
<thead>
<tr>
<!-- TODO: remove in master -->
<t t-set="colspan" t-value="6"/>
<th name="th_description" class="text-left"><span>Description</span></th>
<th name="th_source" class="d-none text-left"><span>Source Document</span></th>
<th name="th_quantity" class="text-right"><span>Quantity</span></th>
<th name="th_priceunit" t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"><span>Unit Price</span></th>
<th name="th_price_unit" t-if="display_discount" t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span>Disc.%</span>
<!-- TODO: remove in master -->
<t t-set="colspan" t-value="colspan+1"/>
</th>
<th name="th_taxes" t-attf-class="text-left {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"><span>Taxes</span></th>
<th name="th_subtotal" class="text-right">
<span groups="account.group_show_line_subtotals_tax_excluded">Amount</span>
<span groups="account.group_show_line_subtotals_tax_included">Total Price</span>
</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<t t-set="current_subtotal" t-value="0"/>
<t t-foreach="o.invoice_line_ids" t-as="line">
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<t t-set="current_subtotal" t-value="current_subtotal + line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
<tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
<t t-if="not line.display_type" name="account_invoice_line_accountable">
<td name="account_invoice_line_name"><span t-field="line.name"/></td>
<td class="text-right">
<span t-field="line.quantity"/>
<span t-field="line.product_uom_id" groups="uom.group_uom"/>
</td>
<td t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.price_unit"/>
</td>
<td t-if="display_discount" t-attf-class="text-right {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.discount"/>
</td>
<td t-attf-class="text-left {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))" id="line_tax_ids"/>
</td>
<td class="text-right o_price_total">
<span t-field="line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<span t-field="line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
</td>
</t>
<t t-if="line.display_type == 'line_section'">
<td colspan="99">
<span t-field="line.name"/>
</td>
<t t-set="current_section" t-value="line"/>
<t t-set="current_subtotal" t-value="0"/>
</t>
<t t-if="line.display_type == 'line_note'">
<td colspan="99">
<span t-field="line.name"/>
</td>
</t>
</tr>
<t t-if="current_section and (line_last or o.invoice_line_ids[line_index+1].display_type == 'line_section')">
<tr class="is-subtotal text-right">
<td colspan="99">
<strong class="mr16">Subtotal</strong>
<span t-esc="current_subtotal" t-options="{"widget": "monetary", "display_currency": o.currency_id}"/>
</td>
</tr>
</t>
</t>
</tbody>
</table>
<div class="clearfix">
<div id="total" class="row">
<div t-attf-class="#{'col-4' if report_type != 'html' else 'col-sm-7 col-md-5'} ml-auto">
<table class="table table-sm;page-break-inside: avoid;">
<tr class="border-black o_subtotal" style="">
<td><strong>Subtotal</strong></td>
<td class="text-right">
<span t-field="o.amount_untaxed"/>
</td>
</tr>
<t t-foreach="o.amount_by_group" t-as="amount_by_group">
<tr style="">
<t t-if="len(o.line_ids.filtered(lambda line: line.tax_line_id)) == 1 and o.amount_untaxed == amount_by_group[2]">
<td><span t-esc="amount_by_group[0]"/></td>
<td class="text-right o_price_total">
<span t-esc="amount_by_group[3]"/>
</td>
</t>
<t t-else="">
<td>
<span t-esc="amount_by_group[0]"/>
<span>&nbsp;<span>on</span>
<t t-esc="amount_by_group[4]"/>
</span>
</td>
<td class="text-right o_price_total">
<span t-esc="amount_by_group[3]"/>
</td>
</t>
</tr>
</t>
<tr class="border-black o_total">
<td><strong>Total</strong></td>
<td class="text-right">
<span t-field="o.amount_total"/>
</td>
</tr>
</table>
</div>
</div>
</div>
<p t-if="o.type in ('out_invoice', 'in_refund')">
Please use the following communication for your payment : <b><span t-field="o.invoice_payment_ref"/></b>
</p>
<p t-if="o.narration" name="comment">
<span t-field="o.narration"/>
</p>
<p t-if="o.invoice_payment_term_id" name="payment_term">
<span t-field="o.invoice_payment_term_id.note"/>
</p>
<p t-if="o.fiscal_position_id.note" name="note">
<span t-field="o.fiscal_position_id.note"/>
</p>
<div id="qrcode" t-if="(o.company_id.qr_code) and (o.currency_id.name == 'EUR') and (o.invoice_partner_bank_id.acc_number != False)">
<p t-if="(o.invoice_partner_bank_id.qr_code_valid)">
<strong class="text-center">Scan me with your banking app.</strong><br/><br/>
<img class="border border-dark rounded" t-att-src="o.invoice_partner_bank_id.build_qr_code_url(o.amount_residual,(o.ref) if (o.ref) else o.name)"/>
</p>
<p t-if="(o.invoice_partner_bank_id.qr_code_valid == False)">
<strong class="text-center">The SEPA QR Code informations are not set correctly.</strong><br/>
</p>
</div>
</div>
</t>
</t>```