~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to report_profit/report/trial_cost.py

  • Committer: Openerp User
  • Author(s): Vauxoo
  • Date: 2012-07-26 20:13:13 UTC
  • Revision ID: openerp@ingelub-erp-20120726201313-cgffyvd3zmqhn2w4

[FIX] bug a la hora de confirmar una orden de venta cuando el producto es de tipo servicio 
tomaba dicho porducto como si este fuera almacenable y tuviera stock cosa que no es asi 

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#
4
4
# Copyright (c) 2010 Vauxoo C.A. (http://openerp.com.ve/) All Rights Reserved.
5
5
#                    Javier Duran <javier@vauxoo.com>
6
 
#
 
6
7
7
#
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
34
34
 
35
35
import time
36
36
from report import report_sxw
 
37
from osv import osv
37
38
import pooler
38
39
 
39
 
 
40
40
class trial_c(report_sxw.rml_parse):
41
41
    '''
42
42
    Book generates purchase and sale
52
52
            'time': time,
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,
67
67
 
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')])
72
 
        if addr_ids:
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')])
 
71
        if addr_ids:                
 
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 '')
76
74
        return addr_inv
 
75
    
 
76
 
77
77
 
78
78
    def _get_rif(self, vat=''):
79
79
        '''
83
83
            return []
84
84
        return vat[2:].replace(' ', '')
85
85
 
 
86
 
86
87
    def _get_data(self, form):
87
88
        pool = pooler.get_pool(self.cr.dbname)
88
89
        line_ids = []
89
 
        cond = ''
90
 
        valor = ''
 
90
        cond=''
 
91
        valor=''
91
92
        res = []
92
93
 
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']
98
99
 
 
100
 
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']
104
106
 
 
107
 
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']
110
113
 
 
114
 
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'
115
118
            valor = ''
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'])
 
125
 
123
126
 
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'
128
130
            valor = ''
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
 
136
138
 
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'
141
142
            valor = ''
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'])
 
149
 
149
150
 
150
151
        if form['u_check'] and form['p_check'] and form['c_check']:
151
 
            vis = (
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'
155
154
            valor = ''
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'])
 
167
 
172
168
 
173
169
        cond = valor and ' and '+vis[1]+'=%s' % valor or cond
174
170
 
176
172
        for i in range(4):
177
173
            self.cr.execute("""select
178
174
                            %s as id,
179
 
                            %s,
 
175
                            %s,        
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,
183
179
                            p_uom_c_id
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]))
187
183
 
188
184
            t = self.cr.fetchall()
189
185
            field_str = 'id,'+vis[2]+',slc,sps,sqc,uda'
190
186
            field_lst = field_str.split(',')
191
187
            d = {}
192
188
            for i in t:
193
 
                d[i[0]] = {}
 
189
                d[i[0]]={}
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])
201
196
 
202
197
            history.append(d)
203
198
 
210
205
            }
211
206
            for i in range(4):
212
207
                during = False
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
219
214
 
220
215
            values['t'] = dtot
221
216
            res.append(values)
224
219
 
225
220
        return res
226
221
 
 
222
 
227
223
    def _get_partner(self, lst_dct):
228
224
        partner_obj = self.pool.get('res.partner')
229
225
        res = ''
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
234
229
                break
235
230
        return res
236
231
 
238
233
        category_obj = self.pool.get('product.category')
239
234
        res = ''
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
244
238
                break
245
239
        return res
246
240
 
248
242
        user_obj = self.pool.get('res.users')
249
243
        res = ''
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
254
247
                break
255
248
        return res
256
249
 
257
250
 
 
251
      
258
252
report_sxw.report_sxw(
259
253
    'report.profit.trial.cost',
260
254
    'report.profit',
261
255
    'addons/report_profit/report/trial_cost.rml',
262
256
    parser=trial_c,
263
257
    header=False
264
 
)
 
258
)