1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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 time
from osv import fields
from osv import osv
class dm_campaign_group(osv.osv): #{{{
_name = "dm.campaign.group"
def _quantity_planned_total(self, cr, uid, ids, name, args, context={}):
result = {}
numeric = True
quantity = 0
groups = self.browse(cr, uid, ids)
for group in groups:
for campaign in group.campaign_ids:
quantity = 0
numeric = True
if campaign.quantity_planned_total.isdigit():
quantity += int(campaign.quantity_planned_total)
else:
result[group.id] = 'Check Segments'
numeric = False
break
if numeric:
result[group.id] = str(quantity)
return result
def _quantity_wanted_total(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
result = dict.fromkeys(ids, '0')
groups = self.browse(cr, uid, ids, context=context)
for group in groups:
quantity = 0
numeric = True
for campaign in group.campaign_ids:
quantity = 0
numeric = True
if campaign.quantity_wanted_total.isdigit():
quantity += int(campaign.quantity_wanted_total)
elif campaign.quantity_wanted_total == "AAA for a Segment":
result[group.id] = 'AAA for a Segment'
numeric = False
break
else:
result[group.id] = 'Check Segments'
numeric = False
break
if numeric:
result[group.id] = str(quantity)
return result
def _quantity_delivered_total(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
result = dict.fromkeys(ids, '0')
groups = self.browse(cr, uid, ids, context=context)
for group in groups:
numeric = True
quantity = 0
for campaign in group.campaign_ids:
quantity = 0
numeric = True
if campaign.quantity_delivered_total.isdigit():
quantity += int(campaign.quantity_delivered_total)
else:
result[group.id] = 'Check Segments'
numeric = False
break
if numeric:
result[group.id] = str(quantity)
return result
def _quantity_usable_total(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
result = dict.fromkeys(ids, '0')
groups = self.browse(cr, uid, ids, context=context)
for group in groups:
quantity = 0
numeric = True
for campaign in group.campaign_ids:
quantity = 0
numeric = True
if campaign.quantity_usable_total.isdigit():
quantity += int(campaign.quantity_usable_total)
else:
result[group.id] = 'Check Segments'
numeric = False
break
if numeric:
result[group.id] = str(quantity)
return result
def _camp_group_code(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
result = dict.fromkeys(ids, '')
offer_code = ''
offer_name = ''
for id in ids:
dt = time.strftime('%Y-%m-%d')
date = dt.split('-')
year = month = ''
if len(date) == 3:
year = date[0][2:]
month = date[1]
final_date = year + month
grp = self.browse(cr, uid, id)
for c in grp.campaign_ids:
if c.offer_id:
d = self.pool.get('dm.offer').browse(cr, uid, c.offer_id.id)
offer_code = d.code
offer_name = d.name
code = '-'.join([final_date, offer_code, offer_name])
result[id] = code
return result
_columns = {
'name': fields.char('Campaign group name', size=64, required=True),
'code': fields.function(_camp_group_code, string='Code', type='char',
method=True, readonly=True),
'campaign_ids': fields.one2many('dm.campaign', 'campaign_group_id',
'Campaigns', domain=[('campaign_group_id', '=', False)],
readonly=True),
# 'quantity_planned_total': fields.function(_quantity_planned_total,
# string='Total planned Quantity', type="char",
# size="64", method=True, readonly=True),
'quantity_wanted_total': fields.function(_quantity_wanted_total,
string='Total Wanted Quantity', type="char", size=64,
method=True, readonly=True),
'quantity_delivered_total': fields.function(_quantity_delivered_total,
string='Total Delivered Quantity', type="char", size=64,
method=True, readonly=True),
'quantity_usable_total': fields.function(_quantity_usable_total,
string='Total Usable Quantity', type="char", size=64,
method=True, readonly=True),
}
dm_campaign_group()#}}}
class dm_campaign(osv.osv): #{{{
_inherit = "dm.campaign"
_columns = {
'campaign_group_id': fields.many2one('dm.campaign.group', 'Campaign group'),
}
dm_campaign()
|