From a1200768d1cb6981c6e5c596e45954d50a38bcea Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Wed, 19 Feb 2020 13:54:39 +0000 Subject: [PATCH] [IMP] l10n_cn: add print option "Voucher" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- addons/l10n_cn/__manifest__.py | 7 +- addons/l10n_cn/models/account_move.py | 26 +++++ addons/l10n_cn/views/account_report.xml | 16 ++++ addons/l10n_cn/views/report_voucher.xml | 121 ++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 addons/l10n_cn/views/account_report.xml create mode 100644 addons/l10n_cn/views/report_voucher.xml diff --git a/addons/l10n_cn/__manifest__.py b/addons/l10n_cn/__manifest__.py index 022963ca202..c8d98034b89 100644 --- a/addons/l10n_cn/__manifest__.py +++ b/addons/l10n_cn/__manifest__.py @@ -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', diff --git a/addons/l10n_cn/models/account_move.py b/addons/l10n_cn/models/account_move.py index f644e9db7d0..129fb9c0509 100644 --- a/addons/l10n_cn/models/account_move.py +++ b/addons/l10n_cn/models/account_move.py @@ -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)) diff --git a/addons/l10n_cn/views/account_report.xml b/addons/l10n_cn/views/account_report.xml new file mode 100644 index 00000000000..501d5c02b19 --- /dev/null +++ b/addons/l10n_cn/views/account_report.xml @@ -0,0 +1,16 @@ + + + + + + Voucher + account.move + qweb-pdf + l10n_cn.report_voucher + l10n_cn.report_voucher + 'Voucher_%s' % (object.name) + form + + + + diff --git a/addons/l10n_cn/views/report_voucher.xml b/addons/l10n_cn/views/report_voucher.xml new file mode 100644 index 00000000000..dad31b7ac02 --- /dev/null +++ b/addons/l10n_cn/views/report_voucher.xml @@ -0,0 +1,121 @@ + + + + + + + + + +