跳至内容
菜单
此问题已终结
1 回复
8572 查看

Hello guys!

We are in Odoo 10.

See this form view. Two prices are displayed with the currency sign ($) at the right :


In a new custom view, I'm trying to display this same currency sign ($). But I'm unable.

My field is defined with :

montant_perte = fields.Float('Montant de la perte', default=1.0)

In my form view (who works well), my field is displayed with :

<field name="montant_perte" widget='monetary' options="{'currency_field': 'currency_id'}" />

No trace of the currency sign $... Grrr.

Could you help.

Thanks


形象
丢弃
编写者 最佳答案

Here is our solution!


In the class :

@api.multi
def _compute_currency_id(self):
        try:
            main_company = self.sudo().env.ref('base.main_company')        except ValueError:
            main_company = self.env['res.company'].sudo().search([], limit=1, order="id")        for template in self:
            template.currency_id = template.company_id.sudo().currency_id.id or main_company.currency_id.id
currency_id = fields.Many2one('res.currency', 'Currency', compute='_compute_currency_id')    
montant_perte = fields.Float('Montant de la perte', default=1.0)


In the form view :

<field name="montant_perte" class="oe_inline" widget='monetary' options="{'currency_field': 'currency_id'}" />
<field name="currency_id" invisible="1" />


形象
丢弃
相关帖文 回复 查看 活动
1
11月 24
1666
1
9月 21
9441
1
1月 24
17049
0
3月 15
3323
1
3月 15
9974