diff --git a/product_usability/__init__.py b/product_usability/__init__.py new file mode 100644 index 0000000..d7d7308 --- /dev/null +++ b/product_usability/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import product diff --git a/product_usability/__openerp__.py b/product_usability/__openerp__.py new file mode 100644 index 0000000..5059ec2 --- /dev/null +++ b/product_usability/__openerp__.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Product Usability module for Odoo +# Copyright (C) 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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': 'Product Usability', + 'version': '0.1', + 'category': 'Product', + 'license': 'AGPL-3', + 'summary': 'Small usability enhancements to the product module', + 'description': """ +Product Usability +================= + +The usability enhancements include: + +* add the object product.price.history in the product template form view (backport of the datamodel of v8) + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['product'], + 'data': [ + 'security/product_security.xml', + 'security/ir.model.access.csv', + 'product_view.xml', + ], + 'installable': True, +} diff --git a/product_usability/product.py b/product_usability/product.py new file mode 100644 index 0000000..25ddbd6 --- /dev/null +++ b/product_usability/product.py @@ -0,0 +1,108 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Product Usability module for Odoo +# Copyright (C) 2015-2016 Akretion (http://www.akretion.com) +# Copyright (C) 2004-2016 Odoo SA (http://www.odoo.com) +# @author Alexis de Lattre +# +# 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 openerp.osv import orm, fields +from openerp import SUPERUSER_ID +import openerp.addons.decimal_precision as dp + + +class ProductTemplate(orm.Model): + _inherit = 'product.template' + + _columns = { + 'price_history_ids': fields.one2many( + 'product.price.history', 'product_template_id', + string='Product Price History') + } + + # All the code below is copyright Odoo SA + def _set_standard_price( + self, cr, uid, product_tmpl_id, value, context=None): + ''' Store the standard price change in order to be able to + retrieve the cost of a product template for a given date''' + if context is None: + context = {} + price_history_obj = self.pool['product.price.history'] + user_company = self.pool['res.users'].browse( + cr, uid, uid, context=context).company_id.id + company_id = context.get('force_company', user_company) + price_history_obj.create(cr, SUPERUSER_ID, { + 'product_template_id': product_tmpl_id, + 'cost': value, + 'company_id': company_id, + 'origin': context.get('product_price_history_origin', False), + }, context=context) + + def create(self, cr, uid, vals, context=None): + product_template_id = super(ProductTemplate, self).create( + cr, uid, vals, context=context) + self._set_standard_price( + cr, uid, product_template_id, + vals.get('standard_price', 0.0), context=context) + return product_template_id + + def write(self, cr, uid, ids, vals, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + if 'standard_price' in vals: + for prod_template_id in ids: + self._set_standard_price( + cr, uid, prod_template_id, + vals['standard_price'], context=context) + res = super(ProductTemplate, self).write( + cr, uid, ids, vals, context=context) + return res + + +class ProductPriceHistory(orm.Model): + # This is a backport of the datamodel of v8 + # The code below is (C) Odoo SA + _name = 'product.price.history' + _rec_name = 'datetime' + _order = 'datetime desc' + + _columns = { + 'company_id': fields.many2one('res.company', required=True), + 'product_template_id': fields.many2one( + 'product.template', 'Product Template', + required=True, ondelete='cascade'), + 'datetime': fields.datetime('Historization Time'), + 'cost': fields.float( + 'Historized Cost', + digits_compute=dp.get_precision('Product Price')), + # the 'origin' field is not in v8, it's an idea of mine ! + 'origin': fields.char('Origin'), + } + + def _get_default_company(self, cr, uid, context=None): + if 'force_company' in context: + return context['force_company'] + else: + company = self.pool['res.users'].browse( + cr, uid, uid, context=context).company_id + return company.id if company else False + + _defaults = { + 'datetime': fields.datetime.now, + 'company_id': _get_default_company, + } diff --git a/product_usability/product_view.xml b/product_usability/product_view.xml new file mode 100644 index 0000000..40c2fe6 --- /dev/null +++ b/product_usability/product_view.xml @@ -0,0 +1,85 @@ + + + + + + + + + + product.price.history.form + product.price.history + +
+ + + + + + + +
+
+
+ + + product.price.history.tree + product.price.history + + + + + + + + + + + + + product.price.history.search + product.price.history + + + + + + + + + + + + + Product Price History + product.price.history + tree,form + {'product_price_history_main_view': True} + + + + + + + usability.product.template.form + product.product + + + + + + + + + + + + + +
+
diff --git a/product_usability/security/ir.model.access.csv b/product_usability/security/ir.model.access.csv new file mode 100644 index 0000000..4c894c7 --- /dev/null +++ b/product_usability/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_product_price_history_employee,prices.history employee,model_product_price_history,base.group_user,1,0,0,0 +access_product_price_history_salemanager,prices.history sale manager,model_product_price_history,base.group_sale_manager,1,1,1,1 diff --git a/product_usability/security/product_security.xml b/product_usability/security/product_security.xml new file mode 100644 index 0000000..7e610e8 --- /dev/null +++ b/product_usability/security/product_security.xml @@ -0,0 +1,19 @@ + + + + + + + + + Product price history multi-company + + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + + + +