~camptocamp/c2c-rd-addons/8.0a

« back to all changes in this revision

Viewing changes to chricar_budget/budget.py

improved logging, improved import structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
 
3
 
#!/usr/bin/python
4
 
# -*- coding: utf-8 -*-
5
2
##############################################
6
3
#
7
4
# ChriCar Beteiligungs- und Beratungs- GmbH
34
31
###############################################
35
32
import time
36
33
from osv import fields,osv
37
 
import pooler
38
 
import sys
 
34
import logging
39
35
 
40
36
class chricar_budget_production(osv.osv):
41
37
     _name = "chricar.budget.production"
42
 
 
43
38
     _columns = {
44
39
          'name'         : fields.char    ('Production Budget', size=64, required=True),
45
40
          'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year',required=True),
68
63
  
69
64
class chricar_budget(osv.osv):
70
65
     _name = "chricar.budget"
 
66
     _logger = logging.getLogger(_name)
71
67
 
72
68
     def product_id_change(self, cr, uid, ids,  product, price_unit_id, uom_id):
73
69
         prod= self.pool.get('product.product').browse(cr, uid,product)
129
125
            product       = line.product_id.id
130
126
            fy_date_start = line.budget_version_id.budget_id.start_date
131
127
            fy_date_stop  = line.budget_version_id.budget_id.end_date
132
 
            #print >>sys.stderr,'harvest ',product, fy_date_start, fy_date_stop
133
128
            cr.execute("""select coalesce(sum(product_qty),0) from stock_move s,
134
129
                                                       stock_location l
135
130
                                 where state='done'
138
133
                                   and product_id = %d
139
134
                                   and to_char(date_expected,'YYYY-MM-DD') between '%s' and '%s'""" % (product,fy_date_start,fy_date_stop))
140
135
            harvest = cr.fetchone()
141
 
            print >>sys.stderr,'harvest ',product, fy_date_start, fy_date_stop, harvest[0]
 
136
            self._logger.debug('harvest `%s` `%s` `%s` `%s`', product, fy_date_start, fy_date_stop, harvest[0])
142
137
            harvest = harvest[0]
143
138
            res[line.id]  = harvest
144
139
        return res
146
141
 
147
142
     def _harvest_net(self, cr, uid, ids, name, args, context=None):
148
143
        res = {}
149
 
        print >>sys.stderr,'harvest yield net'
 
144
        self._logger.debug('harvest yield net')
150
145
        for line in self.browse(cr, uid, ids, context=context):
151
146
            harvest_yield = 0.0
152
147
            harvest = 0.0
153
148
            surface_used  = line.surface
154
149
            if line.harvest_soil:
155
 
                harvest       = line.harvest * (100 - line.harvest_soil ) /100
 
150
                harvest = line.harvest * (100 - line.harvest_soil ) /100
156
151
            else:
157
 
                harvest       = line.harvest
158
 
            print >>sys.stderr,'harvest yield 2',surface_used,harvest
 
152
                harvest = line.harvest
 
153
            self._logger.debug('harvest yield 2 `%s``%s`', surface_used, harvest)
159
154
            if surface_used and surface_used <> 0.0  and  harvest and harvest <> 0.0:
160
155
                 harvest_yield = harvest / surface_used
161
156
            res[line.id]  = harvest_yield
163
158
 
164
159
     def _harvest_yield(self, cr, uid, ids, name, args  , context=None):
165
160
        res = {}
166
 
        print >>sys.stderr,'harvest yield 1'
 
161
        self._logger.debug('harvest yield 1')
167
162
        for line in self.browse(cr, uid, ids, context=context):
168
163
            harvest_yield = 0.0
169
164
            harvest = 0.0
170
165
            surface_used  = line.surface
171
166
            harvest       = line.harvest
172
 
            print >>sys.stderr,'harvest yield 2',surface_used,harvest
 
167
            self._logger.debug('harvest yield 2 `%s` `%s`', surface_used,harvest)
173
168
            if surface_used and surface_used <> 0.0  and  harvest and harvest <> 0.0:
174
169
                 harvest_yield = harvest / surface_used
175
170
            res[line.id]  = harvest_yield
177
172
 
178
173
     def _harvest_yield_diff(self, cr, uid, ids, name, args, context=None):
179
174
        res = {}
180
 
        print >>sys.stderr,'harvest yield 2'
 
175
        self._logger.debug('harvest yield 2')
181
176
        for line in self.browse(cr, uid, ids, context=context):
182
177
            harvest_yield_diff = 0.0
183
178
            yield_qty  = line.yield_qty
184
179
            harvest_net = line.harvest_net
185
 
            print >>sys.stderr,'harvest yield 2',yield_qty,harvest_net
 
180
            self._logger.debug('harvest yield 2 `%s` `%s`', yield_qty,harvest_net)
186
181
            if yield_qty <> 0.0  and harvest_net <> 0.0:
187
182
                 harvest_yield_diff =  ((harvest_net / yield_qty) - 1.0) * 100
188
183
            res[line.id]  = harvest_yield_diff
242
237
 
243
238
class chricar_budget_surface(osv.osv):
244
239
     _name = "chricar.budget.surface"
 
240
     _logger = logging.getLogger(_name)
245
241
 
246
242
     def _surface_location(self, cr, uid, ids, name, args, context=None):
247
243
        res = {}
258
254
            location      = line.location_id.id
259
255
            fy_date_start = line.budget_id.budget_version_id.budget_id.start_date
260
256
            fy_date_stop  = line.budget_id.budget_version_id.budget_id.end_date
261
 
            print >>sys.stderr,'harvest detail ',product,location, fy_date_start, fy_date_stop
 
257
            self._logger.debug('harvest detail `%s` `%s` `%s` `%s`', product, location, fy_date_start, fy_date_stop)
262
258
            cr.execute("""select coalesce(sum(product_qty),0)  from stock_move s,
263
259
                                                       stock_location l
264
260
                                 where state='done'
269
265
                                   and to_char(date_expected,'YYYY-MM-DD') between '%s' and '%s'""" % (product,location,fy_date_start,fy_date_stop))
270
266
            harvest = cr.fetchone()
271
267
            harvest = harvest[0]
272
 
            print >>sys.stderr,'harvest detail 2',product,location, fy_date_start, fy_date_stop,harvest
 
268
            self._logger.debug('harvest detail 2 `%s` `%s` `%s` `%s` `%s`', product, location, fy_date_start, fy_date_stop, harvest)
273
269
            res[line.id]  = harvest
274
270
        return res
275
271
 
280
276
            harvest_yield_detail = 0.0  
281
277
            surface_used_detail  = line.name
282
278
            harvest_detail       = line.harvest
283
 
            print >>sys.stderr,'harvest yield detail',name,surface_used_detail,harvest_detail
 
279
            self._logger.debug('harvest yield detail `%s` `%s` `%s`', name, surface_used_detail, harvest_detail)
284
280
            if surface_used_detail and surface_used_detail <> 0.0 and harvest_detail and harvest_detail <> 0.0:
285
281
                 harvest_yield_detail = harvest_detail / surface_used_detail
286
282
            res[line.id]  = harvest_yield_detail
287
283
        return res
288
284
 
289
 
 
290
285
     _columns = {
291
286
         'budget_id'          : fields.many2one('chricar.budget','Product', required=True),
292
287
         'location_id'        : fields.many2one('stock.location','Location', required=True),
341
336
          'budget_production_id': fields.many2one('chricar.budget.production','Budget Produktion'),
342
337
      }
343
338
c2c_budget_version()
344