summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorARA (OpenERP) <ara@tinyerp.com>2010-10-28 11:37:15 +0530
committerARA (OpenERP) <ara@tinyerp.com>2010-10-28 11:37:15 +0530
commite04b0e3e8a7f370dc9f8feaf5534c0e79eb7a4b6 (patch)
tree2c85a307d4f6ebbd66aa24ccb5979b14013a0304
parent15bc961ead98ca42738cf73aab306bbb167f6403 (diff)
[ADD] ponit_of_sale: add a missining report files
bzr revid: ara@tinyerp.com-20101028060715-8ft3ft16kllhk8pb
-rw-r--r--addons/point_of_sale/report/pos_order_report.py98
-rw-r--r--addons/point_of_sale/report/pos_order_report_view.xml106
-rw-r--r--addons/point_of_sale/report/pos_report.py239
3 files changed, 443 insertions, 0 deletions
diff --git a/addons/point_of_sale/report/pos_order_report.py b/addons/point_of_sale/report/pos_order_report.py
new file mode 100644
index 00000000000..00681457495
--- /dev/null
+++ b/addons/point_of_sale/report/pos_order_report.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# 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/>.
+#
+##############################################################################
+
+import tools
+from osv import fields,osv
+
+class pos_order_report(osv.osv):
+ _name = "report.pos.order"
+ _description = "Point of Sale Orders Statistics"
+ _auto = False
+ _columns = {
+ 'date': fields.date('Date Order', readonly=True),
+ 'year': fields.char('Year', size=4, readonly=True),
+ 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
+ ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
+ ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
+ 'day': fields.char('Day', size=128, readonly=True),
+ 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
+ 'product_id':fields.many2one('product.product', 'Product', readonly=True),
+ 'state': fields.selection([('draft', 'Draft'), ('payment', 'Payment'),
+ ('advance','Advance'),
+ ('paid', 'Paid'), ('done', 'Done'), ('invoiced', 'Invoiced'), ('cancel', 'Cancel')],
+ 'State'),
+ 'user_id':fields.many2one('res.users', 'Salesman', readonly=True),
+ 'price_total':fields.float('Total Price', readonly=True),
+ 'total_discount':fields.float('Total Discount', readonly=True),
+ 'average_price': fields.float('Average Price', readonly=True,group_operator="avg"),
+ 'shop_id':fields.many2one('sale.shop', 'Shop', readonly=True),
+ 'company_id':fields.many2one('res.company', 'Company', readonly=True),
+ 'nbr':fields.integer('# of Lines', readonly=True),
+ 'product_qty':fields.integer('# of Qty', readonly=True),
+ 'journal_id': fields.many2one('account.journal', 'Journal'),
+ 'delay_validation': fields.integer('Delay Validation'),
+ 'delay_payment': fields.integer('Delay Payment'),
+ 'date_validation': fields.date('Validation Date', required=True),
+ 'date_payment': fields.date('Payment Date', required=True),
+ }
+ _order = 'date desc'
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_pos_order')
+ cr.execute("""
+ create or replace view report_pos_order as (
+ select
+ min(l.id) as id,
+ count(*) as nbr,
+ to_date(to_char(s.date_order, 'dd-MM-YYYY'),'dd-MM-YYYY') as date,
+ sum(l.qty * u.factor) as product_qty,
+ sum(l.qty * l.price_unit) as price_total,
+ sum(l.qty * l.price_ded) as total_discount,
+ (sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal(16,2) as average_price,
+ sum(cast(to_char(date_trunc('day',s.date_validation) - date_trunc('day',s.date_order),'DD') as int)) as delay_validation,
+ sum(cast(to_char(date_trunc('day',s.date_payment) - date_trunc('day',s.date_order),'DD') as int)) as delay_payment,
+ to_char(s.date_order, 'YYYY') as year,
+ to_char(s.date_order, 'MM') as month,
+ to_char(s.date_order, 'YYYY-MM-DD') as day,
+ s.partner_id as partner_id,
+ s.state as state,
+ s.user_id as user_id,
+ s.shop_id as shop_id,
+ s.company_id as company_id,
+ s.sale_journal as journal_id,
+ l.product_id as product_id,
+ s.date_validation,
+ s.date_payment
+ from pos_order_line as l
+ left join pos_order s on (s.id=l.order_id)
+ left join product_template pt on (pt.id=l.product_id)
+ left join product_uom u on (u.id=pt.uom_id)
+ group by
+ to_char(s.date_order, 'dd-MM-YYYY'),to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),
+ to_char(s.date_order, 'YYYY-MM-DD'), s.partner_id,s.state,
+ s.user_id,s.shop_id,s.company_id,s.sale_journal,l.product_id,s.date_validation,
+ s.date_payment
+ having
+ sum(l.qty * u.factor) != 0)""")
+
+pos_order_report()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file
diff --git a/addons/point_of_sale/report/pos_order_report_view.xml b/addons/point_of_sale/report/pos_order_report_view.xml
new file mode 100644
index 00000000000..c72a6b6d415
--- /dev/null
+++ b/addons/point_of_sale/report/pos_order_report_view.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <record id="view_report_pos_order_tree" model="ir.ui.view">
+ <field name="name">report.pos.order.tree</field>
+ <field name="model">report.pos.order</field>
+ <field name="type">tree</field>
+ <field name="arch" type="xml">
+ <tree string="Point of Sale Analysis">
+ <field name="date" invisible="1"/>
+ <field name="user_id" invisible="1"/>
+ <field name="year" invisible="1"/>
+ <field name="day" invisible="1"/>
+ <field name="month" invisible="1"/>
+ <field name="partner_id" invisible="1"/>
+ <field name="product_id" invisible="1"/>
+ <field name="shop_id" invisible="1"/>
+ <!--<field name="journal_id" invisible="1"/>-->
+ <field name="date_validation" invisible="1"/>
+ <field name="date_payment" invisible="1"/>
+ <field name="company_id" invisible="1" groups="base.group_multi_company"/>
+ <field name="nbr" sum="# of Lines"/>
+ <field name="product_qty" sum="# of Qty"/>
+ <field name="average_price" sum="Average Price"/>
+ <field name="total_discount" sum="Total Discount"/>
+ <field name="price_total" sum="Total Price"/>
+ <field name="delay_validation"/>
+ <field name="delay_payment"/>
+ <!--<field name="state" invisible="1"/>-->
+ </tree>
+ </field>
+ </record>
+
+ <record id="view_report_pos_order_search" model="ir.ui.view">
+ <field name="name">report.pos.order.search</field>
+ <field name="model">report.pos.order</field>
+ <field name="type">search</field>
+ <field name="arch" type="xml">
+ <search string="Point of Sale Analysis">
+ <group>
+ <filter icon="terp-go-year" string="Year"
+ domain="[('year','=',time.strftime('%%Y'))]"
+ help="POS ordered created during current year"/>
+ <filter icon="terp-go-month" string="Month"
+ domain="[('date','&lt;=',(datetime.date.today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date','&gt;=',(datetime.date.today()-relativedelta(day=1)).strftime('%%Y-%%m-%%d'))]"
+ help="POS ordered created during current month"/>
+ <filter icon="terp-go-month"
+ string="Month -1"
+ separator="1"
+ domain="[('date','&lt;=', (datetime.date.today() - relativedelta(day=31, months=1)).strftime('%%Y-%%m-%%d')),('date','&gt;=',(datetime.date.today() - relativedelta(day=1,months=1)).strftime('%%Y-%%m-%%d'))]"
+ help="POS ordered created last month"/>
+ <separator orientation="vertical"/>
+ <filter icon="terp-go-today"
+ string="Today"
+ name="today"
+ separator="1"
+ domain="[('date','&lt;=', time.strftime('%%Y-%%m-%%d'))]"
+ help="POS ordered created by today"/>
+ <separator orientation="vertical"/>
+ <filter icon="terp-dolar"
+ string="Invoiced"
+ domain="[('state','=',('invoiced'))]"/>
+ <filter icon="terp-dolar"
+ string="Paid"
+ domain="[('state','=',('paid'))]"/>
+ <separator orientation="vertical"/>
+ <field name="partner_id"/>
+ <field name="user_id" widget="selection">
+ <filter icon="terp-personal"
+ string="My Sales"
+ help="My Sales"
+ domain="[('user_id','=',uid)]"/>
+ </field>
+ </group>
+ <newline/>
+ <group expand="0" string="Extended Filters..." groups="base.group_extended">
+ <field name="date_validation"/>
+ <field name="date_payment"/>
+ </group>
+ <newline/>
+ <group expand="1" string="Group By..." colspan="10" col="12">
+ <filter string="Salesman" icon="terp-personal" name="User" context="{'group_by':'user_id'}"/>
+ <filter string="Customer" icon="terp-personal" context="{'group_by':'partner_id'}"/>
+ <separator orientation="vertical"/>
+ <filter string="Product" icon="terp-accessories-archiver" context="{'group_by':'product_id'}"/>
+ <separator orientation="vertical"/>
+ <filter string="Day" icon="terp-go-today" context="{'group_by':'day'}" help="Day of order date"/>
+ <filter string="Month" icon="terp-go-month" context="{'group_by':'month'}" help="Month of order date"/>
+ <filter string="Year" icon="terp-go-year" context="{'group_by':'year'}" help="Year of order date"/>
+ </group>
+ </search>
+ </field>
+ </record>
+
+ <record id="action_report_pos_order_all" model="ir.actions.act_window">
+ <field name="name">Point of Sale Analysis</field>
+ <field name="res_model">report.pos.order</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">tree,graph</field>
+ <field name="search_view_id" ref="view_report_pos_order_search"/>
+ <field name="context">{'search_default_today':1,'search_default_User':1,'group_by_no_leaf':1,'group_by':[]}</field>
+ </record>
+
+ <menuitem action="action_report_pos_order_all" id="menu_report_pos_order_all" parent="menu_point_rep" sequence="3"/>
+ </data>
+</openerp>
diff --git a/addons/point_of_sale/report/pos_report.py b/addons/point_of_sale/report/pos_report.py
new file mode 100644
index 00000000000..cd41eb92944
--- /dev/null
+++ b/addons/point_of_sale/report/pos_report.py
@@ -0,0 +1,239 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# 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 osv import osv, fields
+import time
+import netsvc
+import tools
+
+class report_transaction_pos(osv.osv):
+ _name = "report.transaction.pos"
+ _description = "transaction for the pos"
+ _auto = False
+ _columns = {
+ 'date_create': fields.char('Date', size=16, readonly=True),
+ 'journal_id': fields.many2one('account.journal', 'Sales Journal', readonly=True),
+ 'jl_id': fields.many2one('account.journal', 'Cash Journals', readonly=True),
+ 'user_id': fields.many2one('res.users', 'User', readonly=True),
+ 'no_trans': fields.float('Number of Transaction', readonly=True),
+ 'amount': fields.float('Amount', readonly=True),
+ 'invoice_id': fields.float('Nbr Invoice', readonly=True),
+ 'invoice_am': fields.float('Invoice Amount', readonly=True),
+ 'product_nb': fields.float('Product Nb.', readonly=True),
+ 'disc': fields.float('Disc.', readonly=True),
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_transaction_pos')
+ cr.execute("""
+ create or replace view report_transaction_pos as (
+ select
+ min(absl.id) as id,
+ count(absl.id) as no_trans,
+ sum(absl.amount) as amount,
+ sum(line.price_ded) as disc,
+ to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')::text as date_create,
+ po.user_id as user_id,
+ po.sale_journal as journal_id,
+ abs.journal_id as jl_id,
+ count(po.invoice_id) as invoice_id,
+ count(p.id) as product_nb
+ from
+ account_bank_statement_line as absl,
+ account_bank_statement as abs,
+ product_product as p,
+ pos_order_line as line,
+ pos_order as po
+ where
+ absl.pos_statement_id = po.id and
+ line.order_id=po.id and
+ line.product_id=p.id and
+ absl.statement_id=abs.id
+
+ group by
+ po.user_id,po.sale_journal, abs.journal_id,
+ to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')::text
+ )
+ """)
+ #to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')
+ #to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')::text as date_create,
+report_transaction_pos()
+
+class report_sales_by_user_pos(osv.osv):
+ _name = "report.sales.by.user.pos"
+ _description = "Sales by user"
+ _auto = False
+ _columns = {
+ 'date_order': fields.date('Order Date',required=True, select=True),
+ 'amount': fields.float('Total', readonly=True, select=True),
+ 'qty': fields.float('Quantity', readonly=True, select=True),
+ 'user_id': fields.many2one('res.users', 'User', readonly=True, select=True),
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_sales_by_user_pos')
+ cr.execute("""
+ create or replace view report_sales_by_user_pos as (
+ select
+ min(po.id) as id,
+ to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text as date_order,
+ po.user_id as user_id,
+ sum(pol.qty)as qty,
+ sum((pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0))) as amount
+ from
+ pos_order as po,pos_order_line as pol,product_product as pp,product_template as pt
+ where
+ pt.id=pp.product_tmpl_id and pp.id=pol.product_id and po.id = pol.order_id
+ group by
+ to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text,
+ po.user_id
+
+ )
+ """)
+report_sales_by_user_pos()
+
+class report_sales_by_user_pos_month(osv.osv):
+ _name = "report.sales.by.user.pos.month"
+ _description = "Sales by user monthly"
+ _auto = False
+ _columns = {
+ 'date_order': fields.date('Order Date',required=True, select=True),
+ 'amount': fields.float('Total', readonly=True, select=True),
+ 'qty': fields.float('Quantity', readonly=True, select=True),
+ 'user_id': fields.many2one('res.users', 'User', readonly=True, select=True),
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_sales_by_user_pos_month')
+ cr.execute("""
+ create or replace view report_sales_by_user_pos_month as (
+ select
+ min(po.id) as id,
+ to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text as date_order,
+ po.user_id as user_id,
+ sum(pol.qty)as qty,
+ sum((pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0))) as amount
+ from
+ pos_order as po,pos_order_line as pol,product_product as pp,product_template as pt
+ where
+ pt.id=pp.product_tmpl_id and pp.id=pol.product_id and po.id = pol.order_id
+ group by
+ to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text,
+ po.user_id
+
+ )
+ """)
+report_sales_by_user_pos_month()
+
+class report_sales_by_margin_pos(osv.osv):
+ _name = "report.sales.by.margin.pos"
+ _description = "Sales by margin"
+ _auto = False
+ _columns = {
+ 'product_name':fields.char('Product Name', size=64, readonly=True),
+ 'date_order': fields.date('Order Date',required=True, select=True),
+ 'user_id': fields.many2one('res.users', 'User', readonly=True, select=True),
+ 'qty': fields.float('Qty', readonly=True, select=True),
+ 'net_margin_per_qty':fields.float('Net margin per Qty', readonly=True, select=True),
+ 'total':fields.float('Margin', readonly=True, select=True),
+
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_sales_by_margin_pos')
+ cr.execute("""
+ create or replace view report_sales_by_margin_pos as (
+ select
+ min(pol.id) as id,
+ po.user_id as user_id,
+ pt.name as product_name,
+ to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text as date_order,
+ sum(pol.qty) as qty,
+ pt.list_price-pt.standard_price as net_margin_per_qty,
+ (pt.list_price-pt.standard_price) *sum(pol.qty) as total
+ from
+ product_template as pt,
+ product_product as pp,
+ pos_order_line as pol,
+ pos_order as po
+ where
+ pol.product_id = pp.product_tmpl_id and
+ pp.product_tmpl_id = pt.id and
+ po.id = pol.order_id
+
+ group by
+ pt.name,
+ pt.list_price,
+ pt.standard_price,
+ po.user_id,
+ to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text
+
+ )
+ """)
+report_sales_by_margin_pos()
+
+class report_sales_by_margin_pos_month(osv.osv):
+ _name = "report.sales.by.margin.pos.month"
+ _description = "Sales by margin monthly"
+ _auto = False
+ _columns = {
+ 'product_name':fields.char('Product Name', size=64, readonly=True),
+ 'date_order': fields.date('Order Date',required=True, select=True),
+ 'user_id': fields.many2one('res.users', 'User', readonly=True, select=True),
+ 'qty': fields.float('Qty', readonly=True, select=True),
+ 'net_margin_per_qty':fields.float('Net margin per Qty', readonly=True, select=True),
+ 'total':fields.float('Margin', readonly=True, select=True),
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'report_sales_by_margin_pos_month')
+ cr.execute("""
+ create or replace view report_sales_by_margin_pos_month as (
+ select
+ min(pol.id) as id,
+ po.user_id as user_id,
+ pt.name as product_name,
+ to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text as date_order,
+ sum(pol.qty) as qty,
+ pt.list_price-pt.standard_price as net_margin_per_qty,
+ (pt.list_price-pt.standard_price) *sum(pol.qty) as total
+ from
+ product_template as pt,
+ product_product as pp,
+ pos_order_line as pol,
+ pos_order as po
+ where
+ pol.product_id = pp.product_tmpl_id and
+ pp.product_tmpl_id = pt.id and
+ po.id = pol.order_id
+
+ group by
+ pt.name,
+ pt.list_price,
+ pt.standard_price,
+ po.user_id,
+ to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text
+
+ )
+ """)
+report_sales_by_margin_pos_month()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file