Add module product_usability

This commit is contained in:
Alexis de Lattre
2016-02-26 10:21:46 +01:00
parent 941366ee47
commit 0331fb1290
6 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import product

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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': '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 <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['product'],
'data': [
'security/product_security.xml',
'security/ir.model.access.csv',
'product_view.xml',
],
'installable': True,
}

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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 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,
}

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="product_price_history_form" model="ir.ui.view">
<field name="name">product.price.history.form</field>
<field name="model">product.price.history</field>
<field name="arch" type="xml">
<form string="Product Price History" version="7.0">
<group name="main">
<field name="product_template_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost"/>
<field name="origin"/>
<field name="company_id" groups="base.group_multi_company"/>
</group>
</form>
</field>
</record>
<record id="product_price_history_tree" model="ir.ui.view">
<field name="name">product.price.history.tree</field>
<field name="model">product.price.history</field>
<field name="arch" type="xml">
<tree string="Product Price History" editable="bottom">
<field name="product_template_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost"/>
<field name="origin"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>
<record id="product_price_history_search" model="ir.ui.view">
<field name="name">product.price.history.search</field>
<field name="model">product.price.history</field>
<field name="arch" type="xml">
<search string="Search Product Price History">
<field name="product_template_id"/>
<group string="Group By" name="groupby">
<filter name="product_tmpl_groupby" string="Product" context="{'group_by': 'product_template_id'}"/>
<filter name="datetime_groupby" string="Date" context="{'group_by': 'datetime:month'}"/>
</group>
</search>
</field>
</record>
<record id="product_price_history_action" model="ir.actions.act_window">
<field name="name">Product Price History</field>
<field name="res_model">product.price.history</field>
<field name="view_mode">tree,form</field>
<field name="context">{'product_price_history_main_view': True}</field>
</record>
<menuitem id="product_price_history_menu" action="product_price_history_action"
parent="product.prod_config_main" sequence="55"/>
<!-- product.template form view -->
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">usability.product.template.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<field name="description_purchase" position="after">
<group name="price_history_split">
<group name="price_history" string="Price History" groups="product.group_costing_method">
<field name="price_history_ids" nolabel="1"/>
</group>
<group name="empty"/> <!-- If I don't put this empty group, the group above will take the full width, which make product.price.history difficult to read because there are only 2 fields in tree view -->
</group>
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_product_price_history_employee prices.history employee model_product_price_history base.group_user 1 0 0 0
3 access_product_price_history_salemanager prices.history sale manager model_product_price_history base.group_sale_manager 1 1 1 1

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data noupdate="1">
<record id="product_price_history_rule" model="ir.rule">
<field name="name">Product price history multi-company</field>
<field name="model_id" ref="model_product_price_history"/>
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
</record>
</data>
</openerp>