Odoo v9如何将数字金额转换为文本金额



我想将总金额转换为发票中的字母,为此我使用了amount_to_text函数,但它不起作用,什么都没有显示,这是我的代码

account_invoice.py (C:\Program Files (x86(\Odoo 9.0-20170309\server\openerp\addons\account\models\account_invoice.py

@api.multi
    def onchange_amount(self, amount_total):
        x_Montant = amount_to_text_fr.amount_to_text(amount_total, 'fr', 'DZ')
        return  {'x_Montant': x_Montant}

我在 C:\Program Files (x86(\Odoo 9.0-20170309\server\openerp\addons\account\views\account_invoice_view 中调用此函数

<record id="invoice_form" model="ir.ui.view">
            <field name="name">account.invoice.form</field>
            <field name="model">account.invoice</field>
            <field name="arch" type="xml">
                <form string="Invoice">
                <header>
                   ------
                </header>
                <div class="alert alert-info" role="alert" style="margin-bottom:0px;" attrs="{'invisible': [('has_outstanding','=',False)]}">
                   -----
                        <group>
                            <field name="date_invoice"/>
                            <field name="move_name" invisible="1"/>
                            <field name="user_id" groups="base.group_user" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'account.group_account_invoice']}"/>
                            <label for="currency_id" groups="base.group_multi_currency"/>
                            <div groups="base.group_multi_currency">
                                <field name="currency_id" options="{'no_create': True, 'no_open': True}" class="oe_inline"/>
                                <field name="company_currency_id" invisible="1"/>
                            </div>
                        </group>
                    </group>
                    <field name="sent" invisible="1"/>
                    <notebook colspan="4">
                        <page string="Invoice Lines">
                            <field name="invoice_line_ids" nolabel="1" widget="one2many_list" mode="tree,kanban" context="{'type': type, 'journal_id': journal_id, 'default_invoice_id': id}">
                                <tree string="Invoice Lines" editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="product_id"/>
                                    <field name="name"/>
                                    <field name="company_id" invisible="1"/>
                                    <field name="account_id" groups="account.group_account_user"
                                        domain="[('company_id', '=', parent.company_id), ('internal_type', '=', 'other')]"/>
                                    <field name="account_analytic_id" groups="analytic.group_analytic_accounting"
                                        domain="[('company_id', '=', parent.company_id), ('account_type', '=', 'normal')]"/>
                                    <field name="quantity"/>
                                    <field name="uom_id" groups="product.group_uom"/>
                                    <field name="price_unit"/>
                                    <field name="discount" groups="sale.group_discount_per_so_line"/>
                                    <field name="invoice_line_tax_ids" widget="many2many_tags" context="{'type':parent.type}"
                                        domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]" options="{'no_create': True}"/>
                                    <field name="price_subtotal"/>
                                    <field name="currency_id" invisible="1"/>
                                </tree>
                                <kanban class="o_kanban_mobile">
                               ------
                                </kanban>
                            </field>
                            <group class="oe_subtotal_footer oe_rightoe_subtotal_footer oe_right">
                                <field name="amount_untaxed"/>
                                <field name="amount_tax"/>
                                **<field name="amount_total" class="oe_subtotal_footer_separator" on_change="onchange_amount(amount_total)" />**
                                <field name="payments_widget" colspan="2" nolabel="1" widget="payment"/>
                                <field name="residual" class="oe_subtotal_footer_separator" attrs="{'invisible': [('state', '=', 'draft')]}"/>
                                <field name="reconciled" invisible="1"/>
                                <field name="outstanding_credits_debits_widget" colspan="2" nolabel="1" widget="payment" attrs="{'invisible': [('state', 'not in', 'open')]}"/>
                           **<field name="x_Montant" />**
                           </group>
                            <field name="comment" placeholder="Terms and conditions..."/>
                        </page>

在 odoo 的 9.0 版中,要创建一个更改方法,您必须执行此操作

蟒蛇文件

@api.onchange(amount_total)
def onchange_amount(self):
    self.x_Montant = amount_to_text_fr.amount_to_text(self.amount_total, 'fr', 'DZ')

XML 文件

**<field name="amount_total" class="oe_subtotal_footer_separator" /> **

在 openerp 中,如果您在 XML 字段(旧 api(中定义 onchange 方法:

def onchange_field(self, cr, uid, record_ids, record_id, context=None):
        # compute value...
        return {'value': {'field_name': value, 'other_field_name':value2}}

但在新的 API 中使用装饰器 api.onchange

@api.onchange
def onchange_field(self):
            # compute value...
            self.field_name = value
            self.other_field_name  = value2

最新更新