[REF] purchase: search view of purchase order and form view of merge order wizard
[odoo/odoo.git] / addons / sale_journal / sale_journal_picking_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import fields,osv
23 import tools
24
25 class report_sale_journal_invoice_type_stats(osv.osv):
26     _name = "sale_journal.invoice.type.stats"
27     _description = "Stats on picking by invoice method"
28     _auto = False
29     _columns = {
30         'name': fields.char('Year',size=64,required=False, readonly=True),
31         'invoice_state':fields.selection([
32             ("invoiced","invoiced"),
33             ("2binvoiced","to be invoiced"),
34             ("none","None")
35         ], "Invoice state", readonly=True),
36         'state': fields.selection([
37             ('draft','draft'),
38             ('auto','waiting'),
39             ('confirmed','confirmed'),
40             ('assigned','assigned'),
41             ('done','done'),
42             ('cancel','cancel'),
43         ], 'State', readonly=True),
44         'invoice_type_id':fields.many2one('sale_journal.invoice.type', 'Invoicing method', readonly=True),
45         'quantity': fields.float('Quantities', readonly=True),
46         'price_total': fields.float('Total Price', readonly=True),
47         'price_average': fields.float('Average Price', readonly=True),
48         'count': fields.integer('# of Lines', readonly=True),
49         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
50                           ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
51
52     }
53     _order = 'state,invoice_state,name desc'
54     def init(self, cr):
55         tools.drop_view_if_exists(cr, 'sale_journal_invoice_type_stats')
56         cr.execute("""
57             create or replace view sale_journal_invoice_type_stats as (
58                 select
59                     min(l.id) as id,
60                     to_char(s.date, 'YYYY') as name,
61                     to_char(s.date, 'MM') as month,
62                     s.state,
63                     s.invoice_state,
64                     s.invoice_type_id,
65                     sum(l.product_qty) as quantity,
66                     count(*) as count,
67                     sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0)) as price_total,
68                     (sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0))/sum(l.product_qty))::decimal(16,2) as price_average
69                 from stock_picking s
70                     left join stock_move l on (s.id=l.picking_id)
71                     left join sale_order_line ol on (l.sale_line_id=ol.id)
72                 group by s.invoice_type_id, to_char(s.date, 'YYYY'),to_char(s.date, 'MM'),s.state, s.invoice_state
73                 order by s.invoice_type_id, s.invoice_state, s.state
74             )
75         """)
76 report_sale_journal_invoice_type_stats()
77
78 class report_sale_journal_picking(osv.osv):
79     _name = "sale_journal.picking.stats"
80     _description = "Picking lists by Journal"
81     _auto = False
82     _columns = {
83         'name': fields.char('Year',size=64,required=False, readonly=True),
84         'state': fields.selection([
85             ('draft','draft'),
86             ('auto','waiting'),
87             ('confirmed','confirmed'),
88             ('assigned','assigned'),
89             ('done','done'),
90             ('cancel','cancel'),
91         ], 'State', readonly=True),
92         'journal_id':fields.many2one('sale_journal.picking.journal', 'Journal', readonly=True),
93         'quantity': fields.float('Quantities', readonly=True),
94         'price_total': fields.float('Total Price', readonly=True),
95         'price_average': fields.float('Average Price', readonly=True),
96         'count': fields.integer('# of Lines', readonly=True),
97         'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
98                           ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
99
100     }
101     _order = 'journal_id,name desc,price_total desc'
102     def init(self, cr):
103         tools.drop_view_if_exists(cr, 'sale_journal_picking_stats')
104         cr.execute("""
105             create or replace view sale_journal_picking_stats as (
106                 select
107                     min(l.id) as id,
108                     to_char(s.date, 'YYYY') as name,
109                     to_char(s.date, 'MM') as month,
110                     s.state,
111                     s.journal_id,
112                     sum(l.product_qty) as quantity,
113                     count(*) as count,
114                     sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0)) as price_total,
115                     (sum(l.product_qty*ol.price_unit*(1.0-ol.discount/100.0))/sum(l.product_qty))::decimal(16,2) as price_average
116                 from stock_picking s
117                     right join stock_move l on (s.id=l.picking_id)
118                     right join sale_order_line ol on (l.sale_line_id=ol.id)
119                 group by s.journal_id, to_char(s.date, 'YYYY'),to_char(s.date, 'MM'),s.state
120             )
121         """)
122 report_sale_journal_picking()
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
124