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 change default digits of precision?

By
binfeng
on 7/24/13, 4:45 AM 4,731 views
from openerp.osv import osv, fields

import openerp.addons.decimal_precision as dp

class mrp_bom(osv.osv): _inherit = 'mrp.bom' _columns = {

    'cost_price': fields.related('product_id','cost_price',type='float',**digits_compute = dp.get_precision('Product Price')**,relation="product.product", string="Cost Parts Of Bom", store=False),
        }

I want to inherit ‘mrp.bom' to add a field,but i can not change default digits of precision, How can i do that?

0
Thierry Godin
On 7/24/13, 5:01 AM

Hi , you can change decimal precision by going to :

Configuration / Technical / DB Structure/ Decimal precision

Best regards

Edit : You may take a look at point_of_sale/static/src/js/widget_base.js around line 20

build_currency_template: function(){

            if(this.pos && this.pos.get('currency')){
                this.currency = this.pos.get('currency');
            }else{
                this.currency = {symbol: '$', position: 'after', rounding: 0.01};
            }

            var decimals = Math.max(0,Math.ceil(Math.log(1.0 / this.currency.rounding) / Math.log(10)));

            this.format_currency = function(amount){
                if(typeof amount === 'number'){
                    amount = Math.round(amount*100)/100;
                    amount = amount.toFixed(decimals);
                }
                if(this.currency.position === 'after'){
                    return amount + ' ' + this.currency.symbol;
                }else{
                    return this.currency.symbol + ' ' + amount;
                }
            }

        },

You can change the decimal value here :

this.currency = {symbol: '$', position: 'after', rounding: 0.01};

format_currency() is the function called in pos.xml to display prices.

<t t-name="ProductWidget">
        <li class='product'>
            <a href="#">
                <div class="product-img">
                    <img src='' /> <!-- the product thumbnail -->
                    <t t-if="!widget.model.get('to_weight')">
                        <span class="price-tag">
                            <t t-esc="widget.format_currency(widget.model.get('price'))"/>   
                        </span>
                    </t>
                    <t t-if="widget.model.get('to_weight')">
                        <span class="price-tag">
                            <t t-esc="widget.format_currency(widget.model.get('price'))+'/Kg'"/>
                        </span>
                    </t>
                </div>
                <div class="product-name">
                    <t t-esc="widget.model.get('name')"/>
                </div>
            </a>
        </li>
    </t>

Maybe you have to reload OpenERP

I have changed the 'Product Price' digits to 4,but here inherit cost_price still is 2.

binfeng
on 7/24/13, 5:55 AM

Just for let you know that I have updated my answer.

Thierry Godin
on 7/25/13, 7:24 AM

Thank you very much! It is very hard to me.whatever I will try.

binfeng
on 7/25/13, 11:52 PM

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

0 follower(s)

Stats

Asked: 7/24/13, 4:45 AM
Seen: 4731 times
Last updated: 3/16/15, 8:10 AM