Files
app-odoo/l10n_cn_standard_latest/models/account_move.py
2024-11-04 18:32:45 +08:00

35 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
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'
@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.ids)])
if payment_ids:
domains.append([('res_model', '=', 'account.payment'), ('res_id', 'in', payment_ids.ids)])
return self.env['ir.attachment'].search_count(expression.OR(domains))