4
4
# Copyright (c) 2010 Vauxoo C.A. (http://openerp.com.ve/) All Rights Reserved.
5
5
# Javier Duran <javier@vauxoo.com>
8
8
# WARNING: This program as such is intended to be used by professional
9
9
# programmers who take the whole responsability of assessing all potential
53
53
'get_partner_addr': self._get_partner_addr,
54
54
'get_rif': self._get_rif,
55
'get_data': self._get_data,
55
'get_data':self._get_data,
56
56
'get_partner': self._get_partner,
57
57
'get_category': self._get_category,
58
58
'get_user': self._get_user,
68
68
addr_obj = self.pool.get('res.partner.address')
69
69
addr_inv = 'NO HAY DIRECCION FISCAL DEFINIDA'
70
addr_ids = addr_obj.search(self.cr, self.uid, [(
71
'partner_id', '=', idp), ('type', '=', 'invoice')])
73
addr = addr_obj.browse(self.cr, self.uid, addr_ids[0])
74
addr_inv = (addr.street or '')+' '+(addr.street2 or '')+' '+(addr.zip or '') + ' '+(
75
addr.city or '') + ' ' + (addr.country_id and addr.country_id.name or '') + ', TELF.:'+(addr.phone or '')
70
addr_ids = addr_obj.search(self.cr,self.uid,[('partner_id','=',idp), ('type','=','invoice')])
72
addr = addr_obj.browse(self.cr,self.uid, addr_ids[0])
73
addr_inv = (addr.street or '')+' '+(addr.street2 or '')+' '+(addr.zip or '')+ ' '+(addr.city or '')+ ' '+ (addr.country_id and addr.country_id.name or '')+ ', TELF.:'+(addr.phone or '')
78
78
def _get_rif(self, vat=''):
84
84
return vat[2:].replace(' ', '')
86
87
def _get_data(self, form):
87
88
pool = pooler.get_pool(self.cr.dbname)
93
94
if form['u_check']:
94
vis = ('user', 'user_id', 'user_id', 'user_id')
95
vis=('user','user_id','user_id','user_id')
95
96
xml_id = 'action_profit_user_product_tree'
96
97
if form['user_res_id']:
97
98
valor = form['user_res_id']
99
101
if form['p_check']:
100
vis = ('partner', 'partner_id', 'partner_id', 'partner_id')
102
vis=('partner','partner_id','partner_id','partner_id')
101
103
xml_id = 'action_profit_partner_product_tree'
102
104
if form['partner_res_id']:
103
105
valor = form['partner_res_id']
105
108
if form['c_check']:
106
vis = ('category', 'cat_id', 'cat_id', 'cat_id')
109
vis=('category','cat_id','cat_id','cat_id')
107
110
xml_id = 'action_profit_category_product_tree'
108
111
if form['cat_res_id']:
109
112
valor = form['cat_res_id']
111
115
if form['u_check'] and form['p_check']:
112
vis = ('uxp', '((user_id*1000000)+partner_id)',
113
'user_id,partner_id', 'user_id,partner_id')
116
vis=('uxp','((user_id*1000000)+partner_id)','user_id,partner_id','user_id,partner_id')
114
117
xml_id = 'action_profit_uxp_product_tree'
116
119
if form['user_res_id']:
118
121
if form['partner_res_id']:
119
122
cond = ' and partner_id=%s' % form['partner_res_id']
120
123
if form['user_res_id'] and form['partner_res_id']:
121
cond = ' and user_id=%s and partner_id=%s' % (
122
form['user_res_id'], form['partner_res_id'])
124
cond = ' and user_id=%s and partner_id=%s' % (form['user_res_id'],form['partner_res_id'])
124
127
if form['u_check'] and form['c_check']:
125
vis = ('uxc', '((user_id*1000000)+cat_id)',
126
'user_id,cat_id', 'user_id,cat_id')
128
vis=('uxc','((user_id*1000000)+cat_id)','user_id,cat_id','user_id,cat_id')
127
129
xml_id = 'action_profit_uxc_product_tree'
129
131
if form['user_res_id']:
131
133
if form['cat_res_id']:
132
134
cond = ' and cat_id=%s' % form['cat_res_id']
133
135
if form['user_res_id'] and form['cat_res_id']:
134
cond = ' and user_id=%s and cat_id=%s' % (
135
form['user_res_id'], form['cat_res_id'])
136
cond = ' and user_id=%s and cat_id=%s' % (form['user_res_id'],form['cat_res_id'])
137
139
if form['p_check'] and form['c_check']:
138
vis = ('pxc', '((cat_id*1000000)+partner_id)',
139
'partner_id,cat_id', 'partner_id,cat_id')
140
vis=('pxc','((cat_id*1000000)+partner_id)','partner_id,cat_id','partner_id,cat_id')
140
141
xml_id = 'action_profit_pxc_product_tree'
142
143
if form['partner_res_id']:
144
145
if form['cat_res_id']:
145
146
cond = ' and cat_id=%s' % form['cat_res_id']
146
147
if form['partner_res_id'] and form['cat_res_id']:
147
cond = ' and partner_id=%s and cat_id=%s' % (
148
form['partner_res_id'], form['cat_res_id'])
148
cond = ' and partner_id=%s and cat_id=%s' % (form['partner_res_id'],form['cat_res_id'])
150
151
if form['u_check'] and form['p_check'] and form['c_check']:
152
'upc', '((user_id*100000000000)+(cat_id*1000000)+partner_id)',
153
'user_id,partner_id,cat_id', 'user_id,partner_id,cat_id')
152
vis=('upc','((user_id*100000000000)+(cat_id*1000000)+partner_id)','user_id,partner_id,cat_id','user_id,partner_id,cat_id')
154
153
xml_id = 'action_profit_upc_product_tree'
156
155
if form['partner_res_id']:
158
157
if form['cat_res_id']:
159
158
cond = ' and cat_id=%s' % form['cat_res_id']
160
159
if form['partner_res_id'] and form['cat_res_id']:
161
cond = ' and partner_id=%s and cat_id=%s' % (
162
form['partner_res_id'], form['cat_res_id'])
160
cond = ' and partner_id=%s and cat_id=%s' % (form['partner_res_id'],form['cat_res_id'])
163
161
if form['user_res_id'] and form['partner_res_id']:
164
cond = ' and user_id=%s and partner_id=%s' % (
165
form['user_res_id'], form['partner_res_id'])
162
cond = ' and user_id=%s and partner_id=%s' % (form['user_res_id'],form['partner_res_id'])
166
163
if form['user_res_id'] and form['cat_res_id']:
167
cond = ' and user_id=%s and cat_id=%s' % (
168
form['user_res_id'], form['cat_res_id'])
164
cond = ' and user_id=%s and cat_id=%s' % (form['user_res_id'],form['cat_res_id'])
169
165
if form['user_res_id'] and form['partner_res_id'] and form['cat_res_id']:
170
cond = ' and user_id=%s and partner_id=%s and cat_id=%s' % (
171
form['user_res_id'], form['partner_res_id'], form['cat_res_id'])
166
cond = ' and user_id=%s and partner_id=%s and cat_id=%s' % (form['user_res_id'],form['partner_res_id'],form['cat_res_id'])
173
169
cond = valor and ' and '+vis[1]+'=%s' % valor or cond
176
172
for i in range(4):
177
173
self.cr.execute("""select
180
176
SUM(last_cost) as sum_last_cost,
181
177
SUM(price_subtotal) as sum_price_subtotal,
182
178
SUM(qty_consol) as sum_qty_consol,
184
180
from report_profit p
185
181
where p.name>='%s' and p.name<='%s'%s
186
group by %s,p_uom_c_id""" % (vis[1], vis[2], form[str(i)]['start'], form[str(i)]['stop'], cond, vis[3]))
182
group by %s,p_uom_c_id""" % (vis[1], vis[2], form[str(i)]['start'], form[str(i)]['stop'],cond,vis[3]))
188
184
t = self.cr.fetchall()
189
185
field_str = 'id,'+vis[2]+',slc,sps,sqc,uda'
190
186
field_lst = field_str.split(',')
194
190
if i[0] not in line_ids:
195
191
line_ids.append(i[0])
196
192
if len(i) != len(field_lst):
197
raise wizard.except_wizard(_(
198
'System Error'), _('Incorrect Field List!'))
193
raise wizard.except_wizard(_('System Error'), _('Incorrect Field List!'))
199
194
for j in range(len(i)):
200
d[i[0]].setdefault(field_lst[j], i[j])
195
d[i[0]].setdefault(field_lst[j],i[j])
202
197
history.append(d)
211
206
for i in range(4):
213
if l_id in history[i]:
214
during = [history[i][l_id]]
208
if history[i].has_key(l_id):
209
during = [ history[i][l_id] ]
215
210
values[str(i)] = during and during[0] or ""
216
dtot['slc'] += during and during[0]['slc'] or 0.0
217
dtot['sps'] += during and during[0]['sps'] or 0.0
218
dtot['sqc'] += during and during[0]['sqc'] or 0.0
211
dtot['slc'] += during and during[0]['slc'] or 0.0
212
dtot['sps'] += during and during[0]['sps'] or 0.0
213
dtot['sqc'] += during and during[0]['sqc'] or 0.0
220
215
values['t'] = dtot
221
216
res.append(values)
227
223
def _get_partner(self, lst_dct):
228
224
partner_obj = self.pool.get('res.partner')
230
226
for d in lst_dct:
231
if type(lst_dct[d]) == type(dict()) and 'partner_id' in lst_dct[d] and lst_dct[d]['partner_id']:
232
res = partner_obj.browse(
233
self.cr, self.uid, lst_dct[d]['partner_id']).name
227
if type(lst_dct[d])==type(dict()) and lst_dct[d].has_key('partner_id') and lst_dct[d]['partner_id']:
228
res = partner_obj.browse(self.cr, self.uid, lst_dct[d]['partner_id']).name
238
233
category_obj = self.pool.get('product.category')
240
235
for d in lst_dct:
241
if type(lst_dct[d]) == type(dict()) and 'cat_id' in lst_dct[d] and lst_dct[d]['cat_id']:
242
res = category_obj.browse(
243
self.cr, self.uid, lst_dct[d]['cat_id']).name
236
if type(lst_dct[d])==type(dict()) and lst_dct[d].has_key('cat_id') and lst_dct[d]['cat_id']:
237
res = category_obj.browse(self.cr, self.uid, lst_dct[d]['cat_id']).name
248
242
user_obj = self.pool.get('res.users')
250
244
for d in lst_dct:
251
if type(lst_dct[d]) == type(dict()) and 'user_id' in lst_dct[d] and lst_dct[d]['user_id']:
252
res = user_obj.browse(
253
self.cr, self.uid, lst_dct[d]['user_id']).name
245
if type(lst_dct[d])==type(dict()) and lst_dct[d].has_key('user_id') and lst_dct[d]['user_id']:
246
res = user_obj.browse(self.cr, self.uid, lst_dct[d]['user_id']).name
258
252
report_sxw.report_sxw(
259
253
'report.profit.trial.cost',
261
255
'addons/report_profit/report/trial_cost.rml',