1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2010 Vauxoo C.A. (http://openerp.com.ve/) All Rights Reserved.
5
# Javier Duran <javier@vauxoo.com>
8
# WARNING: This program as such is intended to be used by professional
9
# programmers who take the whole responsability of assessing all potential
10
# consequences resulting from its eventual inadequacies and bugs
11
# End users who are looking for a ready-to-use solution with commercial
12
# garantees and support are strongly adviced to contract a Free Software
15
# This program is Free Software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
##############################################################################
34
from tools.translate import _
37
_transaction_form = '''<?xml version="1.0"?>
38
<form string="Last Cost Price Sum">
39
<separator string="Sum By?" colspan="4"/>
40
<field name="date_start" />
41
<field name="date_end" />
43
<group col="4" colspan="2">
44
<group col="4" colspan="2">
45
<field name="u_check" />
46
<field name="user_res_id" nolabel="1" attrs="{'readonly':[('u_check','!=',True)]}"/>
47
<field name="u_sel" nolabel="1" attrs="{'readonly':[('u_check','!=',True)]}"/>
48
<field name="p_check" />
49
<field name="partner_res_id" nolabel="1" attrs="{'readonly':[('p_check','!=',True)]}"/>
50
<field name="p_sel" nolabel="1" attrs="{'readonly':[('p_check','!=',True)]}"/>
51
<field name="c_check" />
52
<field name="cat_res_id" nolabel="1" attrs="{'readonly':[('c_check','!=',True)]}"/>
53
<field name="c_sel" nolabel="1" attrs="{'readonly':[('c_check','!=',True)]}"/>
59
_transaction_fields = {
60
'date_start': {'string':'Start Date','type':'date','required': True},
61
'date_end': {'string':'End Date','type':'date','required': True},
62
'user_res_id': {'string':'Salesman', 'type':'many2one', 'relation': 'res.users','required':False},
63
'partner_res_id': {'string':'Partner', 'type':'many2one', 'relation': 'res.partner','required':False},
64
'cat_res_id': {'string':'Category', 'type':'many2one', 'relation': 'product.category','required':False},
65
'u_check': {'string':'Check salesman?', 'type':'boolean'},
66
'p_check': {'string':'Check partner?', 'type':'boolean'},
67
'c_check': {'string':'Check category?', 'type':'boolean'},
71
'selection':[('one','1'),('two','2'),('three','3'),('none','No Filter')],
72
'default': lambda *a:'none'
77
'selection':[('one','1'),('two','2'),('three','3'),('none','No Filter')],
78
'default': lambda *a:'none'
83
'selection':[('one','1'),('two','2'),('three','3'),('none','No Filter')],
84
'default': lambda *a:'none'
90
def _data_save(self, cr, uid, data, context):
92
if not form['u_check'] and not form['p_check'] and not form['c_check']:
93
raise wizard.except_wizard(_('User Error'), _('You have to check one box !'))
94
pool = pooler.get_pool(cr.dbname)
95
prod_obj = pool.get('product.product')
96
line_inv_obj = pool.get('account.invoice.line')
104
vis=('user','user_id','user_id','user_id')
105
xml_id = 'action_profit_user_product_tree'
106
if form['user_res_id']:
107
valor = form['user_res_id']
111
vis=('partner','partner_id','partner_id','partner_id')
112
xml_id = 'action_profit_partner_product_tree'
113
if form['partner_res_id']:
114
valor = form['partner_res_id']
118
vis=('category','cat_id','cat_id','cat_id')
119
xml_id = 'action_profit_category_product_tree'
120
if form['cat_res_id']:
121
valor = form['cat_res_id']
124
if form['u_check'] and form['p_check']:
125
vis=('uxp','((user_id*1000000)+partner_id)','user_id,partner_id','user_id,partner_id')
126
xml_id = 'action_profit_uxp_product_tree'
128
if form['user_res_id']:
129
cond = ' and user_id=%s' % form['user_res_id']
130
if form['partner_res_id']:
131
cond = ' and partner_id=%s' % form['partner_res_id']
132
if form['user_res_id'] and form['partner_res_id']:
133
cond = ' and user_id=%s and partner_id=%s' % (form['user_res_id'],form['partner_res_id'])
136
if form['u_check'] and form['c_check']:
137
vis=('uxc','((user_id*1000000)+cat_id)','user_id,cat_id','user_id,cat_id')
138
xml_id = 'action_profit_uxc_product_tree'
140
if form['user_res_id']:
141
cond = ' and user_id=%s' % form['user_res_id']
142
if form['cat_res_id']:
143
cond = ' and cat_id=%s' % form['cat_res_id']
144
if form['user_res_id'] and form['cat_res_id']:
145
cond = ' and user_id=%s and cat_id=%s' % (form['user_res_id'],form['cat_res_id'])
148
if form['p_check'] and form['c_check']:
149
vis=('pxc','((cat_id*1000000)+partner_id)','partner_id,cat_id','partner_id,cat_id')
150
xml_id = 'action_profit_pxc_product_tree'
152
if form['partner_res_id']:
153
cond = ' and partner_id=%s' % form['partner_res_id']
154
if form['cat_res_id']:
155
cond = ' and cat_id=%s' % form['cat_res_id']
156
if form['partner_res_id'] and form['cat_res_id']:
157
cond = ' and partner_id=%s and cat_id=%s' % (form['partner_res_id'],form['cat_res_id'])
160
if form['u_check'] and form['p_check'] and form['c_check']:
161
vis=('upc','((user_id*100000000000)+(cat_id*1000000)+partner_id)','user_id,partner_id,cat_id','user_id,partner_id,cat_id')
162
xml_id = 'action_profit_upc_product_tree'
164
if form['partner_res_id']:
165
cond = ' and partner_id=%s' % form['partner_res_id']
166
if form['cat_res_id']:
167
cond = ' and cat_id=%s' % form['cat_res_id']
168
if form['partner_res_id'] and form['cat_res_id']:
169
cond = ' and partner_id=%s and cat_id=%s' % (form['partner_res_id'],form['cat_res_id'])
170
if form['user_res_id'] and form['partner_res_id']:
171
cond = ' and user_id=%s and partner_id=%s' % (form['user_res_id'],form['partner_res_id'])
172
if form['user_res_id'] and form['cat_res_id']:
173
cond = ' and user_id=%s and cat_id=%s' % (form['user_res_id'],form['cat_res_id'])
174
if form['user_res_id'] and form['partner_res_id'] and form['cat_res_id']:
175
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'])
178
cond = valor and ' and '+vis[1]+'=%s' % valor or cond
180
create or replace view report_profit_%s as (
184
SUM(last_cost) as sum_last_cost,
185
SUM(price_subtotal) as sum_price_subtotal,
186
SUM(qty_consol) as sum_qty_consol,
189
where p.name>='%s' and p.name<='%s'%s
190
group by %s,p_uom_c_id
192
""" % (vis[0],vis[1],vis[2],form['date_start'],form['date_end'],cond,vis[3])
194
sql2 = """SELECT id FROM report_profit_%s""" % vis[0]
199
updated_rep_line = map(lambda x:x[0],res)
201
if None in updated_rep_line:
202
raise wizard.except_wizard(_('User Error'), _('You have to check salesman or product !'))
204
mod_obj = pool.get('ir.model.data')
205
act_obj = pool.get('ir.actions.act_window')
209
result = mod_obj._get_id(cr, uid, 'report_profit', xml_id)
210
id = mod_obj.read(cr, uid, result, ['res_id'])['res_id']
211
# we read the act window
212
result = act_obj.read(cr, uid, id)
213
result['res_id'] = updated_rep_line
218
class wiz_last_cost_sum(wizard.interface):
222
'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('change','Update')]}
226
'result': {'type': 'action', 'action':_data_save, 'state':'end'}
229
wiz_last_cost_sum('profit.update.costprice.sum')
232
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: