Add module pos_sale_report

This commit is contained in:
Alexis de Lattre
2015-02-18 17:04:42 +01:00
parent 587403d009
commit a91d3f79c3
7 changed files with 253 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# POS Sale Report module for Odoo
# Copyright (C) 2015 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/>.
#
##############################################################################
from . import report

View File

@@ -0,0 +1,46 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# POS Sale Report module for Odoo
# Copyright (C) 2015 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': 'POS Sale Report',
'version': '0.1',
'category': 'Point Of Sale',
'license': 'AGPL-3',
'summary': 'Add a graph via on that aggregate sale orders and pos orders',
'description': """
In the *Reporting* menu, add a new entry *POS + Sale Orders Analysis* that show sale statistics per products that aggregate sale orders and pos orders.
Also add direct access to Sales statistics on the Product form view and Product Variants form view (Menu entry *Sales Statistics* in the *More* drop down list).
This module has been written by Alexis de Lattre
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['point_of_sale', 'sale'],
'data': [
'report/pos_sale_report_view.xml',
'product_view.xml',
'security/ir.model.access.csv',
],
'installable': True,
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Add entry in the "More" drop down list in form view -->
<act_window id="product_product_pos_sale_report_action"
key2="client_action_multi"
name="Sales Statistics"
res_model="pos.sale.report"
src_model="product.product"
view_mode="graph"
context="{'search_default_product_id': active_id}"
/>
<act_window id="product_template_pos_sale_report_action"
key2="client_action_multi"
name="Sales Statistics"
res_model="pos.sale.report"
src_model="product.template"
view_mode="graph"
context="{'search_default_product_tmpl_id': active_id}"
/>
</data>
</openerp>

View File

@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# POS Sale Report module for Odoo
# Copyright (C) 2015 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/>.
#
##############################################################################
from . import pos_sale_report

View File

@@ -0,0 +1,82 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# POS Sale Report module for Odoo
# Copyright (C) 2015 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/>.
#
##############################################################################
from openerp import models, fields
from openerp import tools
class pos_sale_report(models.Model):
_name = 'pos.sale.report'
_description = 'POS orders and Sale orders aggregated report'
_auto = False
_rec_name = 'date'
_order = 'date desc'
date = fields.Datetime(string='Order Date', readonly=True)
product_id = fields.Many2one(
'product.product', string='Product Variant', readonly=True)
product_tmpl_id = fields.Many2one(
'product.template', string='Product', readonly=True)
company_id = fields.Many2one(
'res.company', string='Company', readonly=True)
origin = fields.Char(string='Origin', readonly=True)
qty = fields.Float(string='Quantity', readonly=True)
# WARNING : this code doesn't handle uom conversion for the moment
def _sale_order_select(self):
select = """SELECT min(sol.id)*-1 AS id,
so.date_order AS date,
sol.product_id AS product_id,
pp.product_tmpl_id AS product_tmpl_id,
so.company_id AS company_id,
'Sale Order' AS origin,
sum(sol.product_uom_qty) AS qty
FROM sale_order_line sol
LEFT JOIN sale_order so ON so.id = sol.order_id
LEFT JOIN product_product pp ON pp.id = sol.product_id
WHERE so.state NOT IN ('draft', 'sent', 'cancel')
GROUP BY so.date_order, sol.product_id, pp.product_tmpl_id,
so.company_id
"""
return select
def _pos_order_select(self):
select = """SELECT min(pol.id) AS id,
po.date_order AS date,
pol.product_id AS product_id,
pp.product_tmpl_id AS product_tmpl_id,
po.company_id AS company_id,
'Point of Sale' AS origin,
sum(pol.qty) AS qty
FROM pos_order_line pol
LEFT JOIN pos_order po ON po.id = pol.order_id
LEFT JOIN product_product pp ON pp.id = pol.product_id
WHERE po.state IN ('paid', 'done', 'invoiced')
GROUP BY po.date_order, pol.product_id, pp.product_tmpl_id,
po.company_id
"""
return select
def init(self, cr):
tools.drop_view_if_exists(cr, self._table)
cr.execute("CREATE OR REPLACE VIEW %s AS (%s UNION %s)" % (
self._table, self._sale_order_select(), self._pos_order_select()))

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="pos_sale_report_search" model="ir.ui.view">
<field name="name">pos.sale.report.search</field>
<field name="model">pos.sale.report</field>
<field name="arch" type="xml">
<search string="POS orders and Sale orders aggregated report">
<field name="product_tmpl_id"/>
<field name="product_id"/>
<group string="Group By" name="groupby">
<filter name="date_groupby" string="Date" context="{'group_by': 'date'}"/>
<filter name="product_tmpl_groupby" string="Product" context="{'group_by': 'product_tmpl_id'}"/>
<filter name="product_groupby" string="Product Variants" context="{'group_by': 'product_id'}"/>
<filter name="company_groupby" string="Company" context="{'group_by': 'company_id'}"/>
<filter name="origin_groupby" string="Origin" context="{'group_by': 'origin'}"/>
</group>
</search>
</field>
</record>
<record id="pos_sale_report_graph" model="ir.ui.view">
<field name="name">pos.sale.report.graph</field>
<field name="model">pos.sale.report</field>
<field name="arch" type="xml">
<graph string="POS orders and Sale Orders aggregated report" type="pivot">
<field name="origin" type="col"/>
<field name="date" type="row" interval="month"/>
<field name="qty" type="measure"/>
</graph>
</field>
</record>
<record id="pos_sale_report_action" model="ir.actions.act_window">
<field name="name">POS + Sale Orders Analysis</field>
<field name="res_model">pos.sale.report</field>
<field name="view_mode">graph</field>
</record>
<menuitem id="pos_sale_report_title_menu" parent="base.menu_reporting"
name="POS + Sales" sequence="9"/>
<menuitem id="pos_sale_report_menu" action="pos_sale_report_action"
parent="pos_sale_report_title_menu" sequence="10"/>
</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_pos_sale_report_pos_user,Full access on pos.sale.report to POS User,model_pos_sale_report,point_of_sale.group_pos_user,1,1,1,1
access_pos_sale_report_sale_user,Full access on pos.sale.report to Sale User,model_pos_sale_report,base.group_sale_salesman,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_pos_sale_report_pos_user Full access on pos.sale.report to POS User model_pos_sale_report point_of_sale.group_pos_user 1 1 1 1
3 access_pos_sale_report_sale_user Full access on pos.sale.report to Sale User model_pos_sale_report base.group_sale_salesman 1 1 1 1