[12.0][REF] product_usability (#99)

[12.0][REF] product_usability
This commit is contained in:
David Beal
2019-08-14 11:49:51 +02:00
committed by GitHub
15 changed files with 387 additions and 300 deletions

View File

@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import product from . import models
from . import pricelist

View File

@@ -28,7 +28,11 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
'depends': ['product'], 'depends': ['product'],
'data': [ 'data': [
'security/product_security.xml', 'security/product_security.xml',
'product_view.xml', 'views/product_supplierinfo_view.xml',
'views/product_price_history_view.xml',
'views/product_pricelist_view.xml',
'views/product_template_view.xml',
'views/product_view.xml',
], ],
'installable': True, 'installable': True,
} }

View File

@@ -0,0 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import product
from . import product_template
from . import product_supplierinfo
from . import product_price_history
from . import pricelist

View File

@@ -0,0 +1,48 @@
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Raphaël Valyi <rvalyi@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
from odoo.tools.safe_eval import safe_eval
class ProductProduct(models.Model):
_inherit = 'product.product'
default_code = fields.Char(
track_visibility='onchange',
copy=False)
barcode = fields.Char(
track_visibility='onchange',
copy=False)
weight = fields.Float(
track_visibility='onchange')
active = fields.Boolean(
track_visibility='onchange')
price_history_ids = fields.One2many(
comodel_name='product.price.history',
inverse_name='product_id',
string='Product Price History')
_sql_constraints = [(
# Maybe it could be better to have a constrain per company
# but the company_id field is on product.template,
# not on product.product
# If it's a problem, we'll create a company_id field on
# product.product
'default_code_uniq',
'unique(default_code)',
'This internal reference already exists!')]
def show_product_price_history(self):
self.ensure_one()
action = self.env.ref(
'product_usability.product_price_history_action').read()[0]
action['domain'] = safe_eval(action['domain'])
action['domain'].append(('product_id', '=', self.id))
return action

View File

@@ -0,0 +1,16 @@
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Raphaël Valyi <rvalyi@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ProductPriceHistory(models.Model):
_inherit = 'product.price.history'
company_currency_id = fields.Many2one(
related='company_id.currency_id',
readonly=True,
compute_sudo=True,
string='Company Currency')

View File

@@ -0,0 +1,13 @@
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Raphaël Valyi <rvalyi@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo'
name = fields.Many2one(
domain=[('supplier', '=', True), ('parent_id', '=', False)])

View File

@@ -0,0 +1,40 @@
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Raphaël Valyi <rvalyi@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
name = fields.Char(
track_visibility='onchange')
type = fields.Selection(
track_visibility='onchange')
categ_id = fields.Many2one(
track_visibility='onchange')
list_price = fields.Float(
track_visibility='onchange')
sale_ok = fields.Boolean(
track_visibility='onchange')
purchase_ok = fields.Boolean(
track_visibility='onchange')
active = fields.Boolean(
track_visibility='onchange')
def show_product_price_history(self):
self.ensure_one()
products = self.env['product.product'].search(
[('product_tmpl_id', '=', self._context['active_id'])])
action = self.env.ref(
'product_usability.product_price_history_action').read()[0]
action['domain'] = [('product_id', 'in', products.ids)]
return action

View File

@@ -1,73 +0,0 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
name = fields.Char(track_visibility='onchange')
type = fields.Selection(track_visibility='onchange')
categ_id = fields.Many2one(track_visibility='onchange')
list_price = fields.Float(track_visibility='onchange')
sale_ok = fields.Boolean(track_visibility='onchange')
purchase_ok = fields.Boolean(track_visibility='onchange')
active = fields.Boolean(track_visibility='onchange')
def show_product_price_history(self):
self.ensure_one()
products = self.env['product.product'].search(
[('product_tmpl_id', '=', self._context['active_id'])])
action = self.env['ir.actions.act_window'].for_xml_id(
'product_usability', 'product_price_history_action')
action.update({
'domain': "[('product_id', 'in', %s)]" % products.ids,
})
return action
class ProductProduct(models.Model):
_inherit = 'product.product'
default_code = fields.Char(track_visibility='onchange', copy=False)
barcode = fields.Char(track_visibility='onchange', copy=False)
weight = fields.Float(track_visibility='onchange')
active = fields.Boolean(track_visibility='onchange')
price_history_ids = fields.One2many(
'product.price.history', 'product_id',
string='Product Price History')
_sql_constraints = [(
# Maybe it could be better to have a constrain per company
# but the company_id field is on product.template,
# not on product.product
# If it's a problem, we'll create a company_id field on
# product.product
'default_code_uniq',
'unique(default_code)',
'This internal reference already exists!')]
def show_product_price_history(self):
self.ensure_one()
action = self.env['ir.actions.act_window'].for_xml_id(
'product_usability', 'product_price_history_action')
action.update({
'domain': "[('product_id', '=', %d)]" % self.ids[0],
})
return action
class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo'
name = fields.Many2one(
domain=[('supplier', '=', True), ('parent_id', '=', False)])
class ProductPriceHistory(models.Model):
_inherit = 'product.price.history'
company_currency_id = fields.Many2one(
related='company_id.currency_id', readonly=True, compute_sudo=True,
string='Company Currency')

View File

@@ -1,223 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.price.history -->
<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">
<group name="main">
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="create_uid"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</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_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="create_uid"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</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_id"/>
<group string="Group By" name="groupby">
<filter name="product_groupby" string="Product" context="{'group_by': 'product_id'}"/>
<filter name="datetime_groupby" string="Date" context="{'group_by': 'datetime:month'}"/>
<filter name="create_uid_groupby" string="Created by" context="{'group_by': 'create_uid'}"/>
</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 -->
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">usability.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="standard_price" class="oe_inline" position="after">
<button name="show_product_price_history" class="oe_inline oe_link" type="object" string="Show History" context="{'active_id': active_id}"/>
</field>
<!-- Don't make it too big, othesize computers with small resolutions
will see the product name + image under the block of buttons -->
<div class="oe_title" position="attributes">
<attribute name="style">width: 650px;</attribute>
</div>
</field>
</record>
<!-- It also adds on product.product search view -->
<record id="product_template_search_view" model="ir.ui.view">
<field name="name">usability.product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view" />
<field name="arch" type="xml">
<field name="categ_id" position="after">
<field name="seller_ids" string="Supplier" filter_domain="[('seller_ids.name', 'ilike', self)]"/>
</field>
<field name="pricelist_id" position="after">
<group string="Group By" name="groupby">
<filter name="categ_groupby" string="Internal Category" context="{'group_by': 'categ_id'}"/>
<filter name="type_groupby" string="Type" context="{'group_by': 'type'}"/>
</group>
</field>
</field>
</record>
<record id="product_template_tree_view" model="ir.ui.view">
<field name="name">usability.product.template.tree</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="currency_id" invisible="1"/>
</field>
<field name="list_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
<field name="standard_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
</field>
</record>
<!-- product.product -->
<record id="product_product_tree_view" model="ir.ui.view">
<field name="name">usability.product.product.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="arch" type="xml">
<field name="lst_price" position="after">
<field name="currency_id" invisible="1"/>
</field>
<field name="lst_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
</field>
</record>
<!-- product.pricelist -->
<record id="product_pricelist_view_tree" model="ir.ui.view">
<field name="name">usability.product.pricelist.tree</field>
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view_tree"/>
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="company_id" groups="base.group_multi_company"/>
</field>
</field>
</record>
<!-- product.pricelist.item -->
<record id="product_pricelist_item_search" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.search</field>
<field name="model">product.pricelist.item</field>
<field name="arch" type="xml">
<search string="Search Pricelist Items">
<field name="pricelist_id"/>
<field name="product_tmpl_id"/>
<field name="product_id"/>
<field name="categ_id"/>
<group string="Group By" name="groupby">
<filter name="pricelist_groupby" string="Pricelist" context="{'group_by': 'pricelist_id'}"/>
<filter name="applied_on_groupby" string="Apply On" context="{'group_by': 'applied_on'}"/>
<filter name="base_on_groupby" string="Based On" context="{'group_by': 'base'}"/>
<filter name="compute_price_groupby" string="Compute Price" context="{'group_by': 'compute_price'}"/>
<filter name="currency_groupby" string="Currency" context="{'group_by': 'currency_id'}"/>
</group>
</search>
</field>
</record>
<record id="product_pricelist_item_form_view" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.form</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
<field name="arch" type="xml">
<field name="applied_on" position="before">
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
</field>
</field>
</record>
<record id="product_pricelist_item_tree_view" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.tree</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_tree_view"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
</field>
</field>
</record>
<!-- product.supplierinfo -->
<record id="product_supplierinfo_tree_view" model="ir.ui.view">
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product_name"/>
<field name="product_code" string="Supplier Code"/>
</field>
<field name="price" position="after">
<field name="currency_id" groups="base.group_multi_currency"/>
</field>
<field name="min_qty" position="after">
<field name="product_uom" groups="uom.group_uom"/>
</field>
</field>
</record>
<record id="product_supplierinfo_search_view" model="ir.ui.view">
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_search_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product_code" string="Product Supplier Code"/>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.price.history -->
<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">
<group name="main">
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="create_uid"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</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_id" invisible="not context.get('product_price_history_main_view')"/>
<field name="datetime"/>
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
<field name="create_uid"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="company_currency_id" invisible="1"/>
</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_id"/>
<group string="Group By" name="groupby">
<filter name="product_groupby" string="Product" context="{'group_by': 'product_id'}"/>
<filter name="datetime_groupby" string="Date" context="{'group_by': 'datetime:month'}"/>
<filter name="create_uid_groupby" string="Created by" context="{'group_by': 'create_uid'}"/>
</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>
</odoo>

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.pricelist -->
<record id="product_pricelist_view_tree" model="ir.ui.view">
<field name="name">usability.product.pricelist.tree</field>
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view_tree"/>
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="company_id" groups="base.group_multi_company"/>
</field>
</field>
</record>
<!-- product.pricelist.item -->
<record id="product_pricelist_item_search" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.search</field>
<field name="model">product.pricelist.item</field>
<field name="arch" type="xml">
<search string="Search Pricelist Items">
<field name="pricelist_id"/>
<field name="product_tmpl_id"/>
<field name="product_id"/>
<field name="categ_id"/>
<group string="Group By" name="groupby">
<filter name="pricelist_groupby" string="Pricelist" context="{'group_by': 'pricelist_id'}"/>
<filter name="applied_on_groupby" string="Apply On" context="{'group_by': 'applied_on'}"/>
<filter name="base_on_groupby" string="Based On" context="{'group_by': 'base'}"/>
<filter name="compute_price_groupby" string="Compute Price" context="{'group_by': 'compute_price'}"/>
<filter name="currency_groupby" string="Currency" context="{'group_by': 'currency_id'}"/>
</group>
</search>
</field>
</record>
<record id="product_pricelist_item_form_view" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.form</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
<field name="arch" type="xml">
<field name="applied_on" position="before">
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
</field>
</field>
</record>
<record id="product_pricelist_item_tree_view" model="ir.ui.view">
<field name="name">usability.product.pricelist.item.tree</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_tree_view"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.supplierinfo -->
<record id="product_supplierinfo_tree_view" model="ir.ui.view">
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product_name"/>
<field name="product_code" string="Supplier Code"/>
</field>
<field name="price" position="after">
<field name="currency_id" groups="base.group_multi_currency"/>
</field>
<field name="min_qty" position="after">
<field name="product_uom" groups="uom.group_uom"/>
</field>
</field>
</record>
<record id="product_supplierinfo_search_view" model="ir.ui.view">
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_search_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product_code" string="Product Supplier Code"/>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.template -->
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">usability.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="standard_price" class="oe_inline" position="after">
<button name="show_product_price_history" class="oe_inline oe_link" type="object" string="Show History" context="{'active_id': active_id}"/>
</field>
<!-- Don't make it too big, othesize computers with small resolutions
will see the product name + image under the block of buttons -->
<div class="oe_title" position="attributes">
<attribute name="style">width: 650px;</attribute>
</div>
</field>
</record>
<!-- It also adds on product.product search view -->
<record id="product_template_search_view" model="ir.ui.view">
<field name="name">usability.product.template.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view" />
<field name="arch" type="xml">
<field name="categ_id" position="after">
<field name="seller_ids" string="Supplier" filter_domain="[('seller_ids.name', 'ilike', self)]"/>
</field>
<field name="pricelist_id" position="after">
<group string="Group By" name="groupby">
<filter name="categ_groupby" string="Internal Category" context="{'group_by': 'categ_id'}"/>
<filter name="type_groupby" string="Type" context="{'group_by': 'type'}"/>
</group>
</field>
</field>
</record>
<record id="product_template_tree_view" model="ir.ui.view">
<field name="name">usability.product.template.tree</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="currency_id" invisible="1"/>
</field>
<field name="list_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
<field name="standard_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- product.product -->
<record id="product_product_tree_view" model="ir.ui.view">
<field name="name">usability.product.product.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="arch" type="xml">
<field name="lst_price" position="after">
<field name="currency_id" invisible="1"/>
</field>
<field name="lst_price" position="attributes">
<attribute name="widget">monetary</attribute>
</field>
</field>
</record>
</odoo>