![](/img/trans.png)
[英]how to print div from html to qweb report in invoice (website) ? Odoo 14
[英]How to create a customized Invoice Report . Odoo 14
我需要自定義發票格式:header,頁腳,頁面,替換現有的。 我嘗試了這個解決方案,但是在打印發票時,我得到了一個空文件。 請問有什么幫助嗎? 這是我的代碼:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="account_invoices" model="ir.actions.report">
<field name="name">Invoices</field>
<field name="model">account.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">my_module.report_invoice_with_payments</field>
<field name="report_file">my_module.report_invoice_with_payments</field>
<field name="print_report_name">(object._get_report_base_filename())</field>
<field name="attachment">(object.state == 'posted') and ((object.name or 'INV').replace('/','_')+'.pdf')</field>
<field name="binding_model_id" ref="model_account_move"/>
<field name="binding_type">report</field>
<field name="groups_id" eval="[(4, ref('account.group_account_invoice')),
(4, ref('account.group_account_readonly'))]"/>
</record>
<template id="report_invoice_with_payments">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<div class="article" t-attf-data-oe-model="account.move" t-attf-data-oe-id="{{o.id}}">
</div>
<t t-set="lang" t-value="o.invoice_user_id.sudo().lang if o.move_type in ('in_invoice', 'in_refund') else o.partner_id.lang"/>
<t t-set="print_with_payments" t-value="True"/>
<t t-if="o._get_name_invoice_report() == 'my_module.new_report_invoice_document'"
t-call="my_module.new_report_invoice_document" t-lang="lang"/>
</t>
</t>
</template>
</data>
</odoo>
<template id="new_report_invoice_document">
<t t-call="web.external_layout">
....
</template>
有沒有其他解決方案可以做到這一點? 謝謝。
我最近做了這個。 我認為您可以通過以下兩種方式來做到這一點。 Go 到Odoo 設置,然后是Business Documents部分,然后從 go 到Document Layout 。 在這里,您可以根據需要編輯代碼,這將適用於所有文檔。 這里header class代表header。 如果要自定義所有內容,則必須更改每個模板。 您可以從技術 > 用戶界面 > 視圖設置中找到所有模板。
但是如果你想通過自定義模塊來做,那么你需要繼承並用現有的更改替換。 但在這里,您可以制作另一個發票選項,而無需替換現有的選項。 順便說一句,我給你的示例代碼適用於我:
<!-- Custom invoice without payment -->
<template id="module_name.template_id">
<!-- <t t-call="web.html_container">-->
<t t-call="web.basic_layout">
<!-- <t t-foreach="docs" t-as="doc">-->
<div class="oe_structure"/>
<t t-if="not o" t-set="o" t-value="docs"/>
<t t-if="not company">
<!-- Multicompany -->
<t t-if="company_id">
<t t-set="company" t-value="company_id"/>
</t>
<t t-elif="o and 'company_id' in o">
<t t-set="company" t-value="o.company_id.sudo()"/>
</t>
<t t-else="else">
<t t-set="company" t-value="res_company"/>
</t>
</t>
<t t-esc="company.update_scss()"/>
<t t-set="docs" t-value="o.with_context(lang=lang)"/>
<t t-foreach="docs" t-as="o">
<!-- Here goes the custom design for the invoice -->
</t>
</t>
</template>
<!-- Custom invoice with payment -->
<template id="your_module.template_id" inherit_id="your_module.template_id_from_above_module"
primary="True">
<xpath expr="x_path_of_where_you_put_the_payment_section" position="after">
<t t-set="payments_vals" t-value="o._get_reconciled_info_JSON_values()"/>
<t t-set="total_paid" t-value="0"/>
<tr>
<td colspan="2">
<hr class="m-1"/>
</td>
</tr>
<!-- Show partial payments -->
<t t-foreach="payments_vals" t-as="payment_vals">
<t t-set="total_paid" t-value="total_paid + payment_vals['amount']"/>
<tr>
<td class="text-right">
<i class="oe_form_field text-right oe_payment_label">Paid on
<t t-esc="payment_vals['date']" t-options='{"widget": "date"}'/>:
</i>
</td>
<td class="text-right">
<span t-esc="payment_vals['amount']"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
</t>
<tr>
<td></td>
<td>
<hr class="m-1"/>
</td>
</tr>
<tr>
<td class="text-right">
<strong>Total Paid:</strong>
</td>
<td class="text-right">
<strong t-esc="total_paid"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
<!-- End Show partial payments -->
<tr>
<td colspan="2">
<hr class="m-1"/>
</td>
</tr>
<tr>
<td class="text-right">
<span t-if="o.previous_due">Amount Due:</span>
<strong t-else="">Amount Due:</strong>
</td>
<td class="text-right">
<span t-if="o.previous_due" t-field="o.amount_residual"/>
<strong t-else="" t-field="o.amount_residual"/>
</td>
</tr>
<tr t-if="o.previous_due">
<td></td>
<td>
<hr class="m-1"/>
</td>
</tr>
<tr t-if="o.previous_due">
<td class="text-right">
<strong>Total Due:</strong>
</td>
<td class="text-right">
<strong t-field="o.total_due"/>
</td>
</tr>
</xpath>
</template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.