Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to show currency symbol instead of currency name in a treeview?

By
César Bustíos Benites
on 11/7/14, 12:46 PM 2,583 views

I didn't have enough karma yesterday to create a question here. Please, refer to my question on Stack Overflow:

http://stackoverflow.com/questions/26783371/how-to-show-currency-symbol-instead-of-currency-name

Thanks!

1
Marvin Taboada
On 11/7/14, 9:35 PM

Hello César, I have read your question in SO and I think you can use Odoo Model/View inheritance (both of them) in a new custom module to fulfill your requirement.

Background:

* The Model related with Currencies ('res.currency') already provides the currency symbol you require to display.

* 'purchase.order' already has a direct (in v8.0) or indirect relationship (in v7.0) to 'res.currency'.

What to do then?

Add a new "related field" (OpenERP v7.0 terminology) to 'purchase.order' in order to reuse its relationship with 'res.currency' to have the currency symbol available from the 'purchase.order' model.

* Odoo's "class inheritance" (also referred as classical inheritance) for Models allows you to extend an existing model (add new fields, override methods, etc.)

* Odoo's "view inheritance" allows you to redefine existing views.

As you may have already read, Model/View inheritance, in new custom modules, is the preferred way of customizing existing modules.

Sample sources for Odoo 8.0 (an hipotetical 'purchase_currency_symbol' module)

__init__.py

import purchase_currency_symbol

__openerp__.py

{
    'name': "Purchase Order Currency as Symbol",
    'version': "1.0",
    'category': "Purchase Management",
    'summary': 'Purchase Order Currency as Symbol',
    'description': """
Purchase Order Currency as Symbol
=================================

Purchase Order Currency as Symbol.
    """,
    'author': "Foo",
    'website': 'http://www.example.org',
    'depends': ['purchase'],
    'data': [
        'purchase_currency_symbol_view.xml',
    ],
    'installable': True,
    'auto_install': False,
    'application': False,
}

purchase_currency_symbol_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

        <record id="purchase_order_form_inherited" model="ir.ui.view">
            <field name="name">purchase.order.form.inherited</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <data>
                    <field name="currency_id" position="replace">
                        <field name="currency_symbol" groups="base.group_multi_currency"/>
                    </field>
                </data>
            </field>
        </record>

        <record id="purchase_order_tree_inherited" model="ir.ui.view">
            <field name="name">purchase.order.tree.inherited</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_tree"/>
            <field name="arch" type="xml">
                <data>
                    <field name="origin" position="after">
                        <field name="currency_symbol" groups="base.group_multi_currency"/>
                    </field>
                </data>
            </field>
        </record>

    </data>
</openerp>

purchase_currency_symbol.py

from openerp import models, fields


class PurchaseOrder(models.Model):

    _name = "purchase.order"
    _inherit = "purchase.order"

    currency_symbol = fields.Char(string='Currency',
                                  related='currency_id.symbol')

Below sources are for Odoo 8.0, you can adapt the Model in case you're using OpenERP 7.0.

For any doubts, review the official developer oriented documentation at:

* OpenERP 7.0 (Technical Memento)

* Odoo 8.0

Regards,

Marvin

Thank you Marvin!

César Bustíos Benites
on 11/12/14, 11:49 AM

Hi,actually its working but where its reflect in our UI.Looking for your reply

praba
on 11/14/15, 9:03 AM
1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 11/7/14, 10:05 PM

César, do you want the Currency to show as Currency Symbol everywhere or just in the PO?  If you want to show Symbol only in PO, then you can create a related field to get the symbol from currency_id as Marvin as pointed out.  If you want to show Symbol to replace the name everywhere, you have 2 options: 1. override the _rec_name attribute in res.currency.  You can seach for the attribute's name in addons folder to find examples. 2. override the name_get method if res.currency.  The name_get method in the original res.currency model provides some clue (file openerp/addons/base/res/res_currency.py).  In principle, the string that will be display in many2one fields will be dependent on _rec_name attribute, which should be the column name you wish to be displayed (default is the column named "name").  Then it can be altered through the name_get method.

Good point John!

Marvin Taboada
on 11/7/14, 10:35 PM

Thank you that was helpful!

César Bustíos Benites
on 11/12/14, 11:49 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/7/14, 12:46 PM
Seen: 2583 times
Last updated: 3/16/15, 8:10 AM