Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
6158 Lượt xem

Hi Guys,

I need to remove the currency symbol for a specific monetary field.

Is this possible?


Please note that this is for a form view and not for a QWEB view.


Thank you

Eshan Harshana


Ảnh đại diện
Huỷ bỏ

@ESHANG Harshana is asked for form view but this link is for QWEB!

Câu trả lời hay nhất

Hi,
Try this  code
Edit the XML View:
Find the field you want to modify.
It should look something like this in the XML view: 

<field name="amount_total" />

Add the options attribute to the field definition, specifying the 'currency_no_symbol' option:

<field name="amount_total" options="{'currency_no_symbol': True}" />

 

By adding this attribute with the 'currency_no_symbol' option, you are instructing Odoo to display the monetary value without the currency symbol.

Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
<span t-field="line.price_subtotal" t-options='{"widget": "float", "precision": 2}'/>


I think form should support the same options


odoo 17

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I have found another solution. Add below code to your model:

    def formatted_amount(self):

        return self.env['ir.qweb.field.monetary'].value_to_html(

            self.amount,

            {

                'currency': self.currency_id,

                'display_currency': self.currency_id

            }

        ).replace(self.currency_id.symbol, '').strip()

 And then use it like this:

<td class="text-end font-monospace" >

      <t t-esc="record.formatted_amount()" />

</td>​​

A bit tricky but couldn't get other suggestions work.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi, to remove currency symbols from models, try this solution, it worked.

example for a qweb field model in xml:   

"line.price.replace('€', '')" /> 

( replace  '€' with the currency symbol you use)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

In the xml use widget="float" in the specific monetary field

example:

       field name="your_field" widget="float"/>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I have tried the solution from Cybrosys, but it does not work:

span t-field="line.price_total" groups="account.group_show_line_subtotals_tax_included" t-field-options="{'widget': False}"/

Have you ever managed to find a way how to hide the symbol?


Apologies for the weird formatting - Odoo strips all tags in the answer, even when it's formatted as code.

Ảnh đại diện
Huỷ bỏ

I have seen that there is a `no_symbol` Option: https://github.com/odoo/odoo/blob/c00baa010e7981f16bf3047cee6aaee1fc0f7495/addons/web/static/tests/views/fields/monetary_field_tests.js#L930

However, I haven't found a way to use this in a QWeb view. Does anybody have a working solution?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
6053
1
thg 9 17
6445
1
thg 8 17
13552
1
thg 5 17
4575
1
thg 6 16
10502