~pexego/openobject-addons/6.1-pexego-sale_commission

« back to all changes in this revision

Viewing changes to sale_follow_up/report_stock.py

  • Committer: Omar (pexego)
  • Date: 2012-07-27 08:40:22 UTC
  • Revision ID: omar@pexego.es-20120727084022-qp3ludpr3vsuyuf6
[ADD] Traceability modules ported to 6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
 
6
#    $Omar Castiñeira Saavedra$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
"""inherits from stock_report_prodlots adds a column to view, add partner_id because now there are partner_locations or sale locations"""
 
24
 
 
25
from osv import osv, fields
 
26
from tools.translate import _
 
27
from tools.sql import drop_view_if_exists
 
28
 
 
29
#
 
30
# Check if it works with UoM ???
 
31
#
 
32
class stock_report_prodlots(osv.osv):
 
33
    """inherits from stock_report_prodlots adds a columsn to view, add partner_id because now there are partner_locations or sale locations"""
 
34
    _inherit = "stock.report.prodlots"
 
35
    _auto = False
 
36
    _rec_name = 'qty'
 
37
    
 
38
    _columns = {
 
39
            'qty': fields.float('Quantity', readonly=True),
 
40
            'location_id': fields.many2one('stock.location', 'Location', readonly=True, select=True),
 
41
            'product_id': fields.many2one('product.product', 'Product', readonly=True, select=True),
 
42
            'prodlot_id': fields.many2one('stock.production.lot', 'Production Lot', readonly=True, select=True),
 
43
            'partner_id': fields.many2one('res.partner','Customer', readonly=True, select=True),
 
44
    }
 
45
    
 
46
    def init(self, cr):
 
47
        """overwrites the create query"""
 
48
        drop_view_if_exists(cr, 'stock_report_prodlots')
 
49
 
 
50
        cr.execute("""
 
51
            create or replace view stock_report_prodlots as (
 
52
                select max(id) as id,
 
53
                    location_id,
 
54
                    product_id,
 
55
                    prodlot_id,
 
56
                    partner_id,
 
57
                    sum(qty) as qty
 
58
                from (
 
59
                    select -max(sm.id) as id,
 
60
                        sm.location_id,
 
61
                        sm.product_id,
 
62
                        sm.prodlot_id,
 
63
                        sl.partner_id,
 
64
                        -sum(sm.product_qty /uo.factor) as qty
 
65
                    from stock_move as sm
 
66
                    left join stock_location sl
 
67
                        on (sl.id = sm.location_id)
 
68
                    left join product_uom uo
 
69
                        on (uo.id=sm.product_uom)
 
70
                    where state = 'done'
 
71
                    group by sm.location_id, sm.product_id, sm.product_uom, sm.prodlot_id, sl.partner_id
 
72
                    union all
 
73
                    select max(sm.id) as id,
 
74
                        sm.location_dest_id as location_id,
 
75
                        sm.product_id,
 
76
                        sm.prodlot_id,
 
77
                        sl.partner_id,
 
78
                        sum(sm.product_qty /uo.factor) as qty
 
79
                    from stock_move as sm
 
80
                    left join stock_location sl
 
81
                        on (sl.id = sm.location_dest_id)
 
82
                    left join product_uom uo
 
83
                        on (uo.id=sm.product_uom)
 
84
                    where sm.state = 'done'
 
85
                    group by sm.location_dest_id, sm.product_id, sm.product_uom, sm.prodlot_id, sl.partner_id
 
86
                ) as report
 
87
                group by location_id, product_id, prodlot_id, partner_id
 
88
            )""")
 
89
        
 
90
    def unlink(self, cr, uid, ids, context={}):
 
91
        """not allow delete any record, is a database view"""
 
92
        raise osv.except_osv(_('Error !'), _('You cannot delete any record!'))
 
93
 
 
94
        
 
95
stock_report_prodlots()