如何解决如何创建自定义发票报告奥多14
我需要自定义发票格式:页眉、页脚、页面,并替换现有格式。 我尝试了这个解决方案,但是在打印发票时,我得到了一个空文档。 请问有什么帮助吗? 这是我的代码:
<?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>
还有其他解决方案吗? 谢谢。
解决方法
我最近做了这个。我认为你可以通过下面给出的两种方式来做到这一点。转到Odoo 设置,然后转到业务文档部分,然后从那里转到文档布局。您可以在此处根据需要编辑代码,这将适用于所有文档。这里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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。