From 03ac20904948fd0dc33dd9a555a5672a22011756 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 6 Mar 2010 20:55:00 +0100 Subject: [PATCH] [IMP] Decimal Precision module to change the number of digits in real time on floats bzr revid: fp@tinyerp.com-20100306195500-s1t8a7w7gcsch42w --- addons/decimal_precision/__init__.py | 24 ++++++++ addons/decimal_precision/__terp__.py | 41 ++++++++++++++ addons/decimal_precision/decimal_precision.py | 49 +++++++++++++++++ .../decimal_precision_view.xml | 38 +++++++++++++ addons/product/__terp__.py | 2 +- addons/product/product.py | 15 ++--- addons/product/product_data.xml | 55 +++++++++++-------- 7 files changed, 194 insertions(+), 30 deletions(-) create mode 100644 addons/decimal_precision/__init__.py create mode 100644 addons/decimal_precision/__terp__.py create mode 100644 addons/decimal_precision/decimal_precision.py create mode 100644 addons/decimal_precision/decimal_precision_view.xml diff --git a/addons/decimal_precision/__init__.py b/addons/decimal_precision/__init__.py new file mode 100644 index 00000000000..708ad26bbe1 --- /dev/null +++ b/addons/decimal_precision/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +#import decimal_precision +from decimal_precision import get_precision + diff --git a/addons/decimal_precision/__terp__.py b/addons/decimal_precision/__terp__.py new file mode 100644 index 00000000000..c1846f156d2 --- /dev/null +++ b/addons/decimal_precision/__terp__.py @@ -0,0 +1,41 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +{ + "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, +} + + diff --git a/addons/decimal_precision/decimal_precision.py b/addons/decimal_precision/decimal_precision.py new file mode 100644 index 00000000000..54bb501e02c --- /dev/null +++ b/addons/decimal_precision/decimal_precision.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +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 diff --git a/addons/decimal_precision/decimal_precision_view.xml b/addons/decimal_precision/decimal_precision_view.xml new file mode 100644 index 00000000000..0065f7f7c7c --- /dev/null +++ b/addons/decimal_precision/decimal_precision_view.xml @@ -0,0 +1,38 @@ + + + + + + Decimal Precision + decimal.precision + +
+ + + + +
+ + Decimal Precision List + decimal.precision + tree + + + + + + + + + Decimal Accuracy Definitions + decimal.precision + + + +
+
+ + diff --git a/addons/product/__terp__.py b/addons/product/__terp__.py index 8c0a8340984..4128e992c82 100644 --- a/addons/product/__terp__.py +++ b/addons/product/__terp__.py @@ -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": """ diff --git a/addons/product/product.py b/addons/product/product.py index a4a30cba863..87b0622ae9e 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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() diff --git a/addons/product/product_data.xml b/addons/product/product_data.xml index 8037453101e..77ee4adb499 100644 --- a/addons/product/product_data.xml +++ b/addons/product/product_data.xml @@ -1,8 +1,6 @@ - - @@ -14,8 +12,8 @@ Working Time - - + + @@ -23,33 +21,33 @@ PCE 1.0 - 1.0 + 1.0 KGM 1.0 - 1.0 + 1.0 Hour 8.0 - 1.0 + 1.0 Day 1.0 - 1.0 - - + 1.0 + + - + @@ -57,7 +55,7 @@ parameter) will see those record just disappear. Product product.product - + @@ -69,10 +67,10 @@ parameter) will see those record just disappear. Cost Price standard_price - - - - + + + + @@ -80,8 +78,8 @@ parameter) will see those record just disappear. Sale Pricelist sale - - + + @@ -98,7 +96,7 @@ parameter) will see those record just disappear. Default Public Pricelist Line - + @@ -107,12 +105,25 @@ parameter) will see those record just disappear. - + property_valuation_price_type - + + + Sale Price + 2 + + + Purchase Price + 2 + + + Account + 2 + +