This question has been flagged
2 Replies
9963 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!

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

Thank you Marvin!

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

Best Answer

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.

Avatar
Discard

Good point John!

Author

Thank you that was helpful!