[IMP] l10n_cn: add print option "Voucher"

Add an additional report called "Voucher/记帐凭证" to print option in
account.move form view.

A library "cn2an" are required to conver a number to "amount in
words/大写金额" for Chinese financial usage.

Task 2179744

closes odoo/odoo#68121

X-original-commit: 0f6fdce76809af7e965f672970d74594a337f6fb
Signed-off-by: Josse Colpaert <jco@openerp.com>
This commit is contained in:
yhu-odoo
2021-03-18 19:14:14 +00:00
parent d2376c2b03
commit a1200768d1
4 changed files with 169 additions and 1 deletions
+6 -1
View File
@@ -33,6 +33,9 @@ State Data/省份数据
修改小企业会计税率
We added the option to print a voucher which will also
print the amount in words (special Chinese characters for numbers)
correctly when the cn2an library is installed. (e.g. with pip3 install cn2an)
""",
'depends': ['base', 'account', 'l10n_multilang'],
'data': [
@@ -42,7 +45,9 @@ State Data/省份数据
'data/l10n_cn_chart_post_data.xml',
'data/account_tax_template_data.xml',
'data/account_chart_template_data.xml',
'views/account_move_view.xml'
'views/account_move_view.xml',
'views/account_report.xml',
'views/report_voucher.xml',
],
'demo': [
'demo/demo_company.xml',
+26
View File
@@ -3,7 +3,12 @@
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo.osv import expression
try:
from cn2an import an2cn
except ImportError:
an2cn = None
class AccountMove(models.Model):
_inherit = 'account.move'
@@ -15,3 +20,24 @@ class AccountMove(models.Model):
for record in self:
if record.fapiao and (len(record.fapiao) != 8 or not record.fapiao.isdecimal()):
raise ValidationError(_("Fapiao number is an 8-digit number. Please enter a correct one."))
@api.model
def check_cn2an(self):
return an2cn
@api.model
def _convert_to_amount_in_word(self, number):
"""Convert number to ``amount in words`` for Chinese financial usage."""
if not self.check_cn2an():
return None
return an2cn(number, 'rmb')
def _count_attachments(self):
domains = [[('res_model', '=', 'account.move'), ('res_id', '=', self.id)]]
statement_ids = self.line_ids.mapped('statement_id')
payment_ids = self.line_ids.mapped('payment_id')
if statement_ids:
domains.append([('res_model', '=', 'account.bank.statement'), ('res_id', 'in', statement_ids)])
if payment_ids:
domains.append([('res_model', '=', 'account.payment'), ('res_id', 'in', payment_ids)])
return self.env['ir.attachment'].search_count(expression.OR(domains))
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- QWeb Reports -->
<record id="account_voucher_cn" model="ir.actions.report">
<field name="name">Voucher</field>
<field name="model">account.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">l10n_cn.report_voucher</field>
<field name="report_file">l10n_cn.report_voucher</field>
<field name="print_report_name">'Voucher_%s' % (object.name)</field>
<field name="binding_view_types">form</field>
<field name="binding_model_id" ref="model_account_move"/>
</record>
</data>
</odoo>
+121
View File
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="external_layout_boxed" inherit_id="web.external_layout_boxed" primary="True">
<xpath expr="//div[hasclass('o_boxed_header')]" position="replace">
<div class="o_boxed_header">
<div class="row mb8">
<div class="col-3 mb4">
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" style="max-height: 45px;" alt="Logo"/>
</div>
</div>
</div>
</xpath>
</template>
<template id="report_voucher_document">
<t t-set="o" t-value="o.with_context(lang=lang)" />
<t t-set="company" t-value="o.company_id"/>
<t t-call="l10n_cn.external_layout_boxed">
<div class="page">
<div align="center">
<h2>
<span>记账凭证</span>
</h2>
</div>
<div id="company" class="row col-auto">
<span t-field="o.company_id.name"/>
</div>
<div id="informations" class="row">
<!-- offset intentionally for period -->
<div class="col-3 offset-3" name="date">
<strong>日期:</strong>
<span t-field="o.date"/>
</div>
<div class="col-4" t-if="o.name" name="name">
<strong>凭证号:</strong>
<span t-field="o.name"/>
</div>
<div class="col-2">
<strong>附件数:</strong>
<span t-esc="o._count_attachments()"/>
</div>
</div>
<table class="table table-sm o_main_table table-striped" name="entry_line_table">
<thead>
<tr>
<t t-set="colspan" t-value="4"/>
<th name="th_description" class="text-center"><span>摘要</span></th>
<th name="th_account" class="text-center"><span>科目</span></th>
<th name="th_debit" class="text-center"><span>借方</span></th>
<th name="th_credit" class="text-center"><span>贷方</span></th>
</tr>
</thead>
<tbody class="invoice_tbody">
<t t-set="total_debit" t-value="0"/>
<t t-set="total_credit" t-value="0"/>
<t t-foreach="o.line_ids" t-as="line">
<t t-set="total_debit" t-value="total_debit + line.debit"/>
<t t-set="total_credit" t-value="total_credit + line.credit"/>
<tr>
<t name="account_move_line">
<td name="description">
<span t-field="line.name" t-options="{'widget': 'text'}"/>
</td>
<td name="account">
<span t-field="line.account_id.display_name" t-options="{'widget': 'text'}"/>
</td>
<td name="debit">
<span t-if="line.debit != 0" t-field="line.debit"/>
</td>
<td name="credit">
<span t-if="line.credit != 0" t-field="line.credit"/>
</td>
</t>
</tr>
</t>
<t>
<td name="total" colspan="2">
<span>合计:</span>
<span t-esc="o._convert_to_amount_in_word(total_debit)" />
</td>
<td name="total_debit">
<span t-esc="total_debit" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
<td name="total_credit">
<span t-esc="total_credit" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</t>
</tbody>
</table>
<div id="staff" class="row" style="color:black">
<div class="col-4">
<strong>审核:</strong>
</div>
<div class="col-4">
<strong>过账:</strong>
</div>
<div class="col-4">
<strong>制单:</strong>
<span t-esc="o.invoice_user_id.name"/>
</div>
</div>
</div>
</t>
</template>
<template id="report_voucher">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="l10n_cn.report_voucher_document" t-lang="lang"/>
</t>
</t>
</template>
</data>
</odoo>