This question has been flagged
1 Reply
6779 Views

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


Avatar
Discard
Author Best Answer

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" />


Avatar
Discard