diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/l10n_cn/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/l10n_cn/models')
| -rw-r--r-- | addons/l10n_cn/models/__init__.py | 4 | ||||
| -rw-r--r-- | addons/l10n_cn/models/account_move.py | 43 |
2 files changed, 47 insertions, 0 deletions
diff --git a/addons/l10n_cn/models/__init__.py b/addons/l10n_cn/models/__init__.py new file mode 100644 index 00000000..c0124efe --- /dev/null +++ b/addons/l10n_cn/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import account_move diff --git a/addons/l10n_cn/models/account_move.py b/addons/l10n_cn/models/account_move.py new file mode 100644 index 00000000..129fb9c0 --- /dev/null +++ b/addons/l10n_cn/models/account_move.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +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' + + fapiao = fields.Char(string='Fapiao Number', size=8, copy=False, tracking=True) + + @api.constrains('fapiao') + def _check_fapiao(self): + 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)) |
