[IMP] Decimal Precision module to change the number of digits in real time on floats

bzr revid: fp@tinyerp.com-20100306195500-s1t8a7w7gcsch42w
This commit is contained in:
Fabien Pinckaers 2010-03-06 20:55:00 +01:00
parent c1132f4647
commit 03ac209049
7 changed files with 194 additions and 30 deletions

View File

@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#import decimal_precision
from decimal_precision import get_precision

View File

@ -0,0 +1,41 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Decimal Precision Configuration",
"description": """
This module allows to configure the price accuracy you need for different kind
of usage: accounting, sales, purchases, ... The decimal precision is configured
per company.
""",
"author": "Tiny",
"version": "0.1",
"depends": ["base"],
"category" : "Generic Modules/Others",
"init_xml": [],
"update_xml": [
'decimal_precision_view.xml',
],
"demo_xml": [],
"installable": True,
}

View File

@ -0,0 +1,49 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
class decimal_precision(osv.osv):
_name = 'decimal.precision'
_columns = {
'name': fields.char('Usage', size=50, required=True),
'digits': fields.integer('Digits', required=True),
}
_defaults = {
'digits': lambda *a : 2,
}
def write(self, cr, uid, ids, data, *args, **argv):
res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv)
for obj in self.pool.obj_list():
for colname,col in self.pool.get(obj)._columns.items():
if isinstance(col, fields.float):
col.digits_change(cr)
return res
decimal_precision()
def get_precision(application):
def change_digit(cr):
cr.execute('select digits from decimal_precision where name=%s', (application,))
res = cr.fetchone()
if res:
return (16,res[0])
return (16,2)
return change_digit

View File

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_decimal_precision_form">
<field name="name">Decimal Precision</field>
<field name="model">decimal.precision</field>
<field name="arch" type="xml">
<form string="Decimal Precision">
<field name="name" select="1"/>
<field name="digits"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_decimal_precision_tree">
<field name="name">Decimal Precision List</field>
<field name="model">decimal.precision</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Decimal Precision">
<field name="name" select="1"/>
<field name="digits"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_decimal_precision_form">
<field name="name">Decimal Accuracy Definitions</field>
<field name="res_model">decimal.precision</field>
</record>
<menuitem
parent="base.next_id_9"
id="menu_decimal_precision_form"
action="action_decimal_precision_form"/>
</data>
</openerp>

View File

@ -25,7 +25,7 @@
"version" : "1.1",
"author" : "Tiny",
"category" : "Generic Modules/Inventory Control",
"depends" : ["base", "process"],
"depends" : ["base", "process", "decimal_precision"],
"init_xml" : [],
"demo_xml" : ["product_demo.xml"],
"description": """

View File

@ -20,6 +20,7 @@
##############################################################################
from osv import osv, fields
import decimal_precision as dp
import pooler
import math
@ -252,8 +253,8 @@ class product_template(osv.osv):
'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')], 'Requisition Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the requisition request."),
'rental': fields.boolean('Can be Rent'),
'categ_id': fields.many2one('product.category','Category', required=True, change_default=True),
'list_price': fields.float('Sale Price', digits=(16, int(config['price_accuracy'])), help="Base price for computing the customer price. Sometimes called the catalog price."),
'standard_price': fields.float('Cost Price', required=True, digits=(16, int(config['price_accuracy'])), help="Product's cost for accounting stock valuation. It is the base price for the supplier price."),
'list_price': fields.float('Sale Price', digits_compute=dp.get_precision('Sale Price'), help="Base price for computing the customer price. Sometimes called the catalog price."),
'standard_price': fields.float('Cost Price', required=True, digits_compute=dp.get_precision('Account'), help="Product's cost for accounting stock valuation. It is the base price for the supplier price."),
'volume': fields.float('Volume', help="The volume in m3."),
'weight': fields.float('Gross weight', help="The gross weight in Kg."),
'weight_net': fields.float('Net weight', help="The net weight in Kg."),
@ -433,8 +434,8 @@ class product_product(osv.osv):
'virtual_available': fields.function(_product_virtual_available, method=True, type='float', string='Virtual Stock'),
'incoming_qty': fields.function(_product_incoming_qty, method=True, type='float', string='Incoming'),
'outgoing_qty': fields.function(_product_outgoing_qty, method=True, type='float', string='Outgoing'),
'price': fields.function(_product_price, method=True, type='float', string='Customer Price', digits=(16, int(config['price_accuracy']))),
'lst_price' : fields.function(_product_lst_price, method=True, type='float', string='List Price', digits=(16, int(config['price_accuracy']))),
'price': fields.function(_product_price, method=True, type='float', string='Customer Price', digits_compute=dp.get_precision('Sale Price')),
'lst_price' : fields.function(_product_lst_price, method=True, type='float', string='List Price', digits_compute=dp.get_precision('Sale Price')),
'code': fields.function(_product_code, method=True, type='char', string='Code'),
'partner_ref' : fields.function(_product_partner_ref, method=True, type='char', string='Customer ref'),
'default_code' : fields.char('Code', size=64),
@ -443,8 +444,8 @@ class product_product(osv.osv):
'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True),
'ean13': fields.char('EAN13', size=13),
'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the picking order and is mainly used if you use the EDI module."),
'price_extra': fields.float('Variant Price Extra', digits=(16, int(config['price_accuracy']))),
'price_margin': fields.float('Variant Price Margin', digits=(16, int(config['price_accuracy']))),
'price_extra': fields.float('Variant Price Extra', digits_compute=dp.get_precision('Sale Price')),
'price_margin': fields.float('Variant Price Margin', digits_compute=dp.get_precision('Sale Price')),
'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'),
}
@ -651,7 +652,7 @@ class pricelist_partnerinfo(osv.osv):
'name': fields.char('Description', size=64),
'suppinfo_id': fields.many2one('product.supplierinfo', 'Partner Information', required=True, ondelete='cascade'),
'min_quantity': fields.float('Quantity', required=True),
'price': fields.float('Unit Price', required=True, digits=(16, int(config['price_accuracy']))),
'price': fields.float('Unit Price', required=True, digits_compute=dp.get_precision('Purchase Price')),
}
_order = 'min_quantity asc'
pricelist_partnerinfo()

View File

@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!--
Resource: product.uom.categ
-->
@ -14,8 +12,8 @@
</record>
<record id="uom_categ_wtime" model="product.uom.categ">
<field name="name">Working Time</field>
</record>
</record>
<!--
Resource: product.uom
-->
@ -23,33 +21,33 @@
<field name="category_id" ref="product_uom_categ_unit"/>
<field name="name">PCE</field>
<field name="factor">1.0</field>
<field name="factor_inv">1.0</field>
<field name="factor_inv">1.0</field>
</record>
<record id="product_uom_kgm" model="product.uom">
<field name="category_id" ref="product_uom_categ_kgm"/>
<field name="name">KGM</field>
<field name="factor">1.0</field>
<field name="factor_inv">1.0</field>
<field name="factor_inv">1.0</field>
</record>
<record id="uom_hour" model="product.uom">
<field name="name">Hour</field>
<field eval="uom_categ_wtime" name="category_id"/>
<field name="factor">8.0</field>
<field name="factor_inv">1.0</field>
<field name="factor_inv">1.0</field>
</record>
<record id="uom_day" model="product.uom">
<field name="name">Day</field>
<field eval="uom_categ_wtime" name="category_id"/>
<field name="factor">1.0</field>
<field name="factor_inv">1.0</field>
</record>
<field name="factor_inv">1.0</field>
</record>
<!--
... to here, it should be in product_demo but we cant just move it
... to here, it should be in product_demo but we cant just move it
there yet otherwise people who have installed the server (even with the without-demo
parameter) will see those record just disappear.
-->
<!--
Request link
-->
@ -57,7 +55,7 @@ parameter) will see those record just disappear.
<field name="name">Product</field>
<field name="object">product.product</field>
</record>
<!--
Resource: product.price.type
-->
@ -69,10 +67,10 @@ parameter) will see those record just disappear.
<field name="name">Cost Price</field>
<field name="field">standard_price</field>
</record>
<!--
Price list type
-->
@ -80,8 +78,8 @@ parameter) will see those record just disappear.
<field name="name">Sale Pricelist</field>
<field name="key">sale</field>
</record>
<!--
Price list
-->
@ -98,7 +96,7 @@ parameter) will see those record just disappear.
<field name="base" ref="list_price"/>
<field name="name">Default Public Pricelist Line</field>
</record>
<!--
Property
-->
@ -107,12 +105,25 @@ parameter) will see those record just disappear.
<field name="fields_id" search="[('model','=','res.partner'),('name','=','property_product_pricelist')]"/>
<field eval="'product.pricelist,'+str(ref('list0'))" name="value"/>
</record>
<record forcecreate="True" id="property_valuation_price_type" model="ir.property">
<field name="name">property_valuation_price_type</field>
<field name="fields_id" search="[('model','=','res.company'),('name','=','property_valuation_price_type')]"/>
<field eval="'product.price.type,'+str(ref('standard_price'))" name="value"/>
</record>
<record forcecreate="True" id="decimal_sale" model="decimal.precision">
<field name="name">Sale Price</field>
<field name="digits">2</field>
</record>
<record forcecreate="True" id="decimal_purchase" model="decimal.precision">
<field name="name">Purchase Price</field>
<field name="digits">2</field>
</record>
<record forcecreate="True" id="decimal_account" model="decimal.precision">
<field name="name">Account</field>
<field name="digits">2</field>
</record>
</data>
</openerp>