~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_analytic_package/account_analytic_package.py

  • Committer: Fabien Pinckaers
  • Date: 2007-10-09 04:14:07 UTC
  • Revision ID: fp@tinyerp.com-8d2e4f75dc6d6c13fac16cd67c11e4e250988012
Portals:
        improvements
NEW MODULE: account_analytic_package
        Manage Services & Activity Units
        Include statistics and views for the partner portal
        Developped for managing Tiny ERP partners contracts
NEW MODULE: portal_analytic_package
        Portal for account_analytic_package


Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- 
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
5
#                                       Fabien Pinckaers <fp@tiny.Be>
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
import operator
 
30
from osv import osv, fields
 
31
 
 
32
class product_product(osv.osv):
 
33
        _inherit = "product.product"
 
34
        _columns = {
 
35
                'package_weight': fields.float('Package Weight', digits=(16,2)),
 
36
        }
 
37
        _defaults = {
 
38
                'package_weight': lambda *args: 0.0
 
39
        }
 
40
product_product()
 
41
 
 
42
class crm_case_section(osv.osv):
 
43
        _inherit = "crm.case.section"
 
44
        _columns = {
 
45
                'package_weight': fields.float('Package Weight', digits=(16,2)),
 
46
        }
 
47
        _defaults = {
 
48
                'package_weight': lambda *args: 0.0
 
49
        }
 
50
crm_case_section()
 
51
 
 
52
class account_analytic_line_package(osv.osv):
 
53
        _name = "account.analytic.line.package"
 
54
        _auto = False
 
55
        def init(self, cr):
 
56
                cr.execute("""
 
57
                        CREATE OR REPLACE VIEW account_analytic_line_package AS (
 
58
                                select
 
59
                                        l.id,
 
60
                                        l.name,
 
61
                                        l.date,
 
62
                                        a.partner_id,
 
63
                                        a.id as account_id,
 
64
                                        l.product_id,
 
65
                                        p.package_weight as unit_weight,
 
66
                                        p.package_weight*l.unit_amount as total_weight,
 
67
                                        l.unit_amount 
 
68
                                from 
 
69
                                        account_analytic_line l 
 
70
                                left join 
 
71
                                        account_analytic_account a on (l.account_id=a.id) 
 
72
                                left join 
 
73
                                        product_product p on (p.id=l.product_id) 
 
74
                                where 
 
75
                                        l.product_id is not null and
 
76
                                        p.package_weight<>0
 
77
                        )
 
78
                """)
 
79
        _columns = {
 
80
                'name': fields.char('Name', size=128, readonly=True, select=1),
 
81
                'date': fields.date('Date', readonly=True, select=1),
 
82
                'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
 
83
                'account_id': fields.many2one('account.analytic.account', 'Account', readonly=True),
 
84
                'product_id': fields.many2one('product.product', 'Product', select=2, readonly=True),
 
85
                'unit_amount': fields.float('Quantity', readonly=True),
 
86
                'unit_weight': fields.float('Unit Weight', readonly=True),
 
87
                'total_weight': fields.float('Total Weight', readonly=True),
 
88
        }
 
89
account_analytic_line_package()
 
90
 
 
91
class account_analytic_line_package_month(osv.osv):
 
92
        _name = "account.analytic.line.package.month"
 
93
        _auto = False
 
94
        def init(self, cr):
 
95
                cr.execute("""
 
96
                        CREATE OR REPLACE VIEW account_analytic_line_package_month AS (
 
97
                                select
 
98
                                        min(l.id) as id,
 
99
                                        substring(l.date,0,8)||'-01' as name,
 
100
                                        a.partner_id,
 
101
                                        l.product_id,
 
102
                                        sum(p.package_weight*l.unit_amount) as total_weight,
 
103
                                        sum(case when p.package_weight>0 then p.package_weight*l.unit_amount else 0 end) as total_activity,
 
104
                                        sum(case when p.package_weight<0 then -p.package_weight*l.unit_amount else 0 end) as total_service
 
105
                                from 
 
106
                                        account_analytic_line l 
 
107
                                left join 
 
108
                                        account_analytic_account a on (l.account_id=a.id) 
 
109
                                left join 
 
110
                                        product_product p on (p.id=l.product_id) 
 
111
                                where 
 
112
                                        l.product_id is not null and
 
113
                                        p.package_weight<>0
 
114
                                group by
 
115
                                        l.product_id,
 
116
                                        a.partner_id,
 
117
                                        substring(l.date,0,8)
 
118
                        )
 
119
                """)
 
120
        _columns ={
 
121
                'name': fields.date('Date', readonly=True, select=1),
 
122
                'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
 
123
                'product_id': fields.many2one('product.product', 'Product', select=2, readonly=True),
 
124
                'total_weight': fields.float('Total Weight', readonly=True),
 
125
                'total_activity': fields.float('Total Activity', readonly=True),
 
126
                'total_service': fields.float('Total Service', readonly=True),
 
127
        }
 
128
account_analytic_line_package_month()