pos_usability: add group by on pos category on products search view
Add link to products from pos.category form view (same as on product.category form view)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import pos
|
||||
from . import product
|
||||
|
||||
@@ -18,7 +18,13 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['point_of_sale'],
|
||||
'data': ['pos_view.xml'],
|
||||
'depends': [
|
||||
'point_of_sale',
|
||||
'product_usability', # I need it for the groupby on the search view product.product_template_search_view
|
||||
],
|
||||
'data': [
|
||||
'pos_view.xml',
|
||||
'product_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
25
pos_usability/pos.py
Normal file
25
pos_usability/pos.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PosCategory(models.Model):
|
||||
_inherit = 'pos.category'
|
||||
|
||||
product_count = fields.Integer(
|
||||
'# Products', compute='_compute_product_count',
|
||||
help="The number of products under this point of sale category "
|
||||
"(does not consider the children categories)")
|
||||
|
||||
# inspired by the code of odoo/addons/product/models/product.py
|
||||
def _compute_product_count(self):
|
||||
read_group_res = self.env['product.template'].read_group(
|
||||
[('pos_categ_id', 'in', self.ids)],
|
||||
['pos_categ_id'], ['pos_categ_id'])
|
||||
group_data = dict(
|
||||
(data['pos_categ_id'][0], data['pos_categ_id_count']) for data
|
||||
in read_group_res)
|
||||
for pos_categ in self:
|
||||
pos_categ.product_count = group_data.get(pos_categ.id, 0)
|
||||
@@ -36,19 +36,25 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- put option "available in POS" at the top of product form view -->
|
||||
<record id="product_template_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.pos.product.template</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="point_of_sale.product_template_form_view"/>
|
||||
<record id="product_pos_category_form_view" model="ir.ui.view">
|
||||
<field name="name">pos.category.form</field>
|
||||
<field name="model">pos.category</field>
|
||||
<field name="inherit_id" ref="point_of_sale.product_pos_category_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='pos']/field[@name='available_in_pos']" position="replace"/>
|
||||
<xpath expr="//div[@name='options']" position="inside">
|
||||
<div name="available_in_pos">
|
||||
<field name="available_in_pos"/>
|
||||
<label for="available_in_pos"/>
|
||||
<div class="oe_left" position="before">
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button class="oe_stat_button"
|
||||
name="%(product.product_template_action_all)d"
|
||||
icon="fa-th-list"
|
||||
type="action"
|
||||
context="{'search_default_pos_categ_id': active_id}">
|
||||
<div class="o_form_field o_stat_info">
|
||||
<span class="o_stat_value"><field name="product_count"/></span>
|
||||
<span class="o_stat_text"> Products</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</xpath>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
42
pos_usability/product_view.xml
Normal file
42
pos_usability/product_view.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
© 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<!-- put option "available in POS" at the top of product form view -->
|
||||
<record id="product_template_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.pos.product.template</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="point_of_sale.product_template_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='pos']/field[@name='available_in_pos']" position="replace"/>
|
||||
<xpath expr="//div[@name='options']" position="inside">
|
||||
<div name="available_in_pos">
|
||||
<field name="available_in_pos"/>
|
||||
<label for="available_in_pos"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_template_search_view" model="ir.ui.view">
|
||||
<field name="name">pos_usability.product.template.search</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product_usability.product_template_search_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="categ_id" position="after">
|
||||
<field name="pos_categ_id" filter_domain="[('pos_categ_id', 'child_of', self)]"/>
|
||||
</field>
|
||||
<filter name="categ_groupby" position="after">
|
||||
<filter name="pos_categ_groupby" string="Point of Sale Category" context="{'group_by': 'pos_categ_id'}"/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user