我想将总金额转换为发票中的字母,因为我使用函数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>
答案 0 :(得分:0)
在odoo的9.0版本中,要创建一个on change方法,你必须这样做
Python文件
@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" /> **
答案 1 :(得分:0)
在openerp中,如果在XML字段(旧api)中定义onchange方法:
from("file:src/main/resources/test?noop=true")
.to("jms:queue:PDF")
.marshal().base64()
.to("jms:queue:BASE64_PDF")
但在新的API中使用装饰器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}}