~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to cost_structure/wizard/compute_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:
4
4
#    Module Writen to OpenERP, Open Source Management Solution
5
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
6
6
#    All Rights Reserved
7
 
# Credits######################################################
8
 
#    Coded by: Vauxoo C.A.
 
7
###############Credits######################################################
 
8
#    Coded by: Vauxoo C.A.           
9
9
#    Planified by: Nhomar Hernandez
10
10
#    Audited by: Vauxoo C.A.
11
11
#############################################################################
21
21
#
22
22
#    You should have received a copy of the GNU Affero General Public License
23
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
##########################################################################
25
 
 
26
 
from openerp.osv import osv, fields
27
 
import openerp.tools as tools
28
 
from openerp.tools.translate import _
29
 
 
 
24
################################################################################
 
25
 
 
26
from osv import fields, osv
 
27
import tools
 
28
from tools.translate import _
30
29
from tools import config
31
 
import openerp.netsvc as netsvc
 
30
import netsvc
32
31
import decimal_precision as dp
33
32
from DateTime import DateTime
34
33
import time
35
34
import datetime
36
35
invo_cost = {}
37
36
 
38
 
 
39
 
class compute_cost(osv.TransientModel):
40
 
 
 
37
class compute_cost(osv.osv_memory):
 
38
 
 
39
    
41
40
    _name = 'compute.cost'
42
41
    _columns = {
43
 
        'product_ids': fields.many2many('product.product', 'product_rel',
44
 
            'product1', 'product2', 'Product',
45
 
            help="Select the product to compute cost"),
46
 
        'product': fields.boolean('Product',
47
 
            help="To select compute by product"),
48
 
        'categ': fields.boolean('Category',
49
 
            help="To select compute by category"),
50
 
        'bolfili': fields.boolean('Boolean FIFO LIFO'),
51
 
        'categ_ids': fields.many2many('product.category', 'categ_rel',
52
 
            'categ1', 'categ2', 'Product Category',
53
 
            help="Select the category to compute cost"),
54
 
        'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year',
55
 
            help="Fiscal Year to search invoice between indicated period"),
56
 
        'period_id': fields.many2one('account.period', 'Period',
57
 
            help="Period to search invoice between indicated period"),
58
 
        'all': fields.boolean('ALL', help="To compute cost for all products"),
59
 
        'fifo': fields.boolean('FIFO',
60
 
            help="To compute cost FIFO for products"),
61
 
        'lifo': fields.boolean('LIFO',
62
 
            help="To compute cost LIFO for products"),
63
 
 
 
42
        'product_ids':fields.many2many('product.product','product_rel','product1','product2','Product',help="Select the product to compute cost"),
 
43
        'product':fields.boolean('Product',help="To select compute by product"),
 
44
        'categ':fields.boolean('Category',help="To select compute by category"),
 
45
        'bolfili':fields.boolean('Boolean FIFO LIFO'),
 
46
        'categ_ids':fields.many2many('product.category','categ_rel','categ1','categ2','Product Category',help="Select the category to compute cost"),
 
47
        'fiscalyear_id':fields.many2one('account.fiscalyear','Fiscal Year',help="Fiscal Year to search invoice between indicated period"),
 
48
        'period_id':fields.many2one('account.period','Period',help="Period to search invoice between indicated period"),
 
49
        'all':fields.boolean('ALL',help="To compute cost for all products"),
 
50
        'fifo':fields.boolean('FIFO',help="To compute cost FIFO for products"),
 
51
        'lifo':fields.boolean('LIFO',help="To compute cost LIFO for products"),
 
52
        
64
53
    }
65
 
 
66
 
    def compute_cost_fifo(self, cr, uid, dic_comp, dic_vent, dic_nc_com, dic_nc_vent, context={}):
 
54
    
 
55
    
 
56
    def compute_cost_fifo(self,cr,uid,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
67
57
        '''
68
58
        Method that performs the actual FIFO cost, receiving the dictionaries of every movement,
69
59
        to perform the calculations for caesarean
76
66
        invoice_obj = self.pool.get('account.invoice')
77
67
        rec_com = {}
78
68
        rec_vent = {}
79
 
        [rec_com.update({invoice_obj.browse(cr, uid, e[-1],
80
 
                            context=context).parent_id.id:e[0]})
81
 
                            for i in dic_nc_com for e in dic_nc_com.get(i)]
82
 
        [rec_vent.update({invoice_obj.browse(cr, uid, h[-1],
83
 
                            context=context).parent_id.id:h[0]})
84
 
                            for g in dic_nc_vent for h in dic_nc_vent.get(g)]
 
69
        [rec_com.update({invoice_obj.browse(cr,uid,e[-1],context=context).parent_id.id:e[0]}) for i in dic_nc_com for e in dic_nc_com.get(i)]
 
70
        [rec_vent.update({invoice_obj.browse(cr,uid,h[-1],context=context).parent_id.id:h[0]}) for g in dic_nc_vent for h in dic_nc_vent.get(g)]
85
71
        cont = 0
86
72
        cont_qty = 0
87
73
        price = 0
88
74
        for i in dic_comp:
89
 
            aux = (d for d in dic_comp.get(i, False))
 
75
            aux = (d for d in dic_comp.get(i,False))
90
76
            try:
91
77
                fifo = aux and aux.next()
92
78
            except:
93
 
                raise osv.except_osv(_('Invalid action !'), _(
94
 
                    "Impossible to calculate FIFO not have invoices\
95
 
                    in this period  "))
96
 
            qty_aux = fifo and fifo[0] in rec_com.keys() and fifo[
97
 
                3] - rec_com.get(fifo[0], False) or fifo[3]
 
79
                raise osv.except_osv(_('Invalid action !'),_("Impossible to calculate FIFO not have invoices in this period  "))
 
80
            qty_aux = fifo and fifo[0] in rec_com.keys() and fifo[3] - rec_com.get(fifo[0],False) or fifo[3]
98
81
            cost_aux = fifo and fifo[1]
99
 
 
 
82
            
100
83
            for d in dic_vent.get(i):
101
 
                cont = d[-1] in rec_vent.keys() and\
102
 
                                            (cont + d[0]) - rec_vent.get(d[-1],
103
 
                                            False) or cont + d[0]
104
 
 
 
84
                cont = d[-1] in rec_vent.keys() and (cont + d[0]) - rec_vent.get(d[-1],False) or cont + d[0]
 
85
                
105
86
                if cont <= qty_aux:
106
87
                    price = (d[0] * cost_aux) + price
107
88
                else:
111
92
                    fifo = aux.next()
112
93
                    cont_qty = cont + cont_qty
113
94
                    cont = 0
114
 
                    qty_aux = fifo and fifo[0] in rec_com.keys() and fifo[
115
 
                        3] - rec_com.get(fifo[0], False) or fifo[3]
 
95
                    qty_aux = fifo and fifo[0] in rec_com.keys() and fifo[3] - rec_com.get(fifo[0],False) or fifo[3]
116
96
                    cost_aux = fifo and fifo[1]
117
97
        cont_qty = cont + cont_qty
118
98
        if price and cont_qty or cont:
119
 
 
120
 
            cost = price / (cont_qty > 0 and cont_qty or cont > 0 and cont)
 
99
            
 
100
            cost = price / (cont_qty > 0  and cont_qty or cont > 0 and cont)
121
101
        return True
122
 
 
123
 
    def search_invoice(self, cr, uid, ids, dict, type, period, company, date,
124
 
                        context=None):
 
102
    
 
103
    def search_invoice(self,cr,uid,ids,dict,type,period,company,date,context=None):
125
104
        '''
126
 
        Return a list of invoices ids that have products sended in the dict
 
105
        Return a list of invoices ids that have products sended in the dict 
127
106
        #~ ('period_id','=',period),
128
107
        '''
129
108
        if context is None:
130
109
            context = {}
131
110
        invo_obj = self.pool.get('account.invoice')
132
111
        if date:
133
 
            invo_ids = invo_obj.search(
134
 
                cr, uid, [(
135
 
                    'invoice_line.product_id', 'in', tuple(dict.keys())),
136
 
                    ('type', '=', type),
137
 
                    ('company_id',
138
 
                     '=', company),
139
 
                    ('date_invoice', '>=', date)],
140
 
                order='date_invoice')
141
 
 
 
112
            invo_ids = invo_obj.search(cr,uid,[('invoice_line.product_id','in', tuple(dict.keys())),
 
113
                                                    ('type','=',type),
 
114
                                                    ('company_id','=',company),
 
115
                                                    ('date_invoice','>=',date)],
 
116
                                                    order='date_invoice')
 
117
    
142
118
        else:
143
 
            invo_ids = invo_obj.search(
144
 
                cr, uid, [(
145
 
                    'invoice_line.product_id', 'in', tuple(dict.keys())),
146
 
                    ('type', '=', type),
147
 
                    ('state', 'in', (
148
 
                     'open', 'paid')),
149
 
                    ('company_id', '=', company)],
150
 
                order='date_invoice')
 
119
            invo_ids = invo_obj.search(cr,uid,[('invoice_line.product_id','in', tuple(dict.keys())),
 
120
                                                    ('type','=',type),
 
121
                                                    ('state','in',('open','paid')),
 
122
                                                    ('company_id','=',company)],
 
123
                                                    order='date_invoice')
151
124
        return invo_ids
152
 
 
153
 
    def compute_actual_cost(self, cr, uid, ids, dic_comp, dic_vent, dic_nc_com,
154
 
                                                    dic_nc_vent, context={}):
 
125
    
 
126
    def compute_actual_cost(self,cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
155
127
        '''
156
128
        Method that performs the actual average cost, receiving the dictionaries of every movement,
157
129
        to perform the calculations for caesarean
170
142
            #~ print " dic_nc_vent.get(i)", dic_nc_vent.get(431)
171
143
            #~ print " dic_comp.get(i)", dic_comp.get(431)
172
144
            #~ print " dic_vent.get(i)", dic_vent.get(431)
173
 
            product_brw = product_obj.browse(cr, uid, i, context=context)
174
 
            if dic_comp.get(i, False) and len(dic_comp[i]) > 0:
 
145
            product_brw = product_obj.browse(cr,uid,i,context=context)
 
146
            if dic_comp.get(i,False) and len(dic_comp[i]) > 0:
175
147
                qty = (sum([a[3] for a in dic_comp.get(i)])) - \
176
148
                      (sum([a[3] for a in dic_nc_com.get(i)])) + \
177
149
                      (sum([a[0] for a in dic_nc_vent.get(i)])) - \
180
152
                        (sum([a[2] for a in dic_nc_com.get(i)])) + \
181
153
                        (sum([a[1] for a in dic_nc_vent.get(i)])) - \
182
154
                        (sum([a[2] for a in dic_vent.get(i)]))
183
 
 
184
 
                if qty > 0:
 
155
                
 
156
                if qty > 0 :
185
157
                    cost = price / qty
186
 
                    aux.update({i: [price, qty, cost and
187
 
                                    cost, dic_comp[i] and
188
 
                                    dic_comp[i][0] and dic_comp[i][0][4] or []]})
 
158
                    aux.update({i:[price,qty,cost and cost,dic_comp[i] and dic_comp[i][0] and dic_comp[i][0][4] or [] ]})
189
159
                    date = dic_comp.get(i)[-1] and dic_comp.get(i)[-1][0] and \
190
 
                        invoice_obj.browse(cr, uid, dic_comp.get(
191
 
                                           i)[-1][0], context=context).date_invoice
 
160
                           invoice_obj.browse(cr,uid,dic_comp.get(i)[-1][0],context=context).date_invoice
192
161
                    date = date and date.split('-') or False
193
162
                    time = date and date[2].split(' ')
194
163
                    time = time and time[1].split(":")
195
 
                    date = date and time and datetime.datetime(
196
 
                                                        int(date[0]),
197
 
                                                        int(date[1]),
198
 
                                                        int(date[2][0:2]),
199
 
                                                        int(time[0]),
200
 
                                                        int(time[1]),
201
 
                                                        int(time[2])) or False
202
 
                    date = date and date + datetime.timedelta(
203
 
                        seconds=1) or dat.strftime('%Y/%m/%d %H:%M:%S')
204
 
 
205
 
                    if context.get('not_write', False):
 
164
                    date = date and time and datetime.datetime(int(date[0]), int(date[1]), int(date[2][0:2]),int(time[0]),int(time[1]),int(time[2])) or False
 
165
                    date = date and date + datetime.timedelta(seconds=1) or dat.strftime('%Y/%m/%d %H:%M:%S')
 
166
                    
 
167
                    if context.get('not_write',False):
206
168
                        pass
207
169
                    else:
208
 
                        if context.get('invoice_cancel', False):
209
 
                            product_obj.write(cr, uid, [product_brw.id],
210
 
                                              {'cost_ult': cost,
211
 
                                               'date_cost_ult': date,
212
 
                                               'qty_ult': aux.get(i)
213
 
                                               and aux.get(i)[1],
214
 
                                               'ult_om': aux.get(i)[-1] or [],
215
 
                                               'date_ult_om': date},
216
 
                                              context=context)
217
 
 
218
 
                        if product_brw.property_cost_structure and\
219
 
                        product_brw.cost_ult > 0:
220
 
                            product_obj.write(cr, uid, [product_brw.id],
221
 
                                  {'cost_ult': cost,
222
 
                                   'date_cost_ult': date,
223
 
                                   'qty_ult': aux.get(i)
224
 
                                   and aux.get(i)[1],
225
 
                                   'cost_ant': product_brw.cost_ult,
226
 
                                   'qty_ant': product_brw.qty_ult,
227
 
                                   'date_cost_ant': product_brw.date_cost_ult,
228
 
                                   'ult_om': aux.get(i)[-1] or [],
229
 
                                   'date_ult_om': date,
230
 
                                   'ant_om': product_brw.ult_om
231
 
                                   and product_brw.ult_om.id
232
 
                                   or [],
233
 
                                   'date_ant_om': product_brw.date_ult_om},
234
 
                                  context=context)
 
170
                        if context.get('invoice_cancel',False):
 
171
                            product_obj.write(cr,uid,[product_brw.id],{'cost_ult':cost,'date_cost_ult':date ,'qty_ult':aux.get(i) and aux.get(i)[1] ,'ult_om':aux.get(i)[-1] or [] ,'date_ult_om': date },context=context)
 
172
                       
 
173
                        if product_brw.property_cost_structure and product_brw.cost_ult > 0:
 
174
                            product_obj.write(cr,uid,[product_brw.id],{'cost_ult':cost,'date_cost_ult':date ,'qty_ult':aux.get(i) and aux.get(i)[1]  , 'cost_ant':product_brw.cost_ult ,'qty_ant':product_brw.qty_ult ,'date_cost_ant':product_brw.date_cost_ult ,'ult_om':aux.get(i)[-1] or [] ,'date_ult_om': date , 'ant_om':product_brw.ult_om and product_brw.ult_om.id or [],'date_ant_om':product_brw.date_ult_om },context=context)
235
175
                        else:
236
 
                            product_obj.write(cr, uid, [product_brw.id],
237
 
                                              {'cost_ult': cost,
238
 
                                               'date_cost_ult': date,
239
 
                                               'qty_ult': aux.get(i)
240
 
                                               and aux.get(i)[1],
241
 
                                               'ult_om': aux.get(i)[-1] or [],
242
 
                                               'date_ult_om': date},
243
 
                                                            context=context)
 
176
                            product_obj.write(cr,uid,[product_brw.id],{'cost_ult':cost,'date_cost_ult':date,'qty_ult':aux.get(i) and aux.get(i)[1]  ,'ult_om':aux.get(i)[-1] or [] ,'date_ult_om': date },context=context)
244
177
        return aux
245
 
 
246
 
    def update_dictionary(self, cr, uid, ids, dict, inv_ids, purchase,
247
 
                            context=None):
248
 
        '''
249
 
        Update a dict send with move all this product
250
 
        '''
251
 
 
 
178
        
 
179
    def update_dictionary(self,cr,uid,ids,dict,inv_ids,purchase,context=None):
 
180
        '''
 
181
        Update a dict send with move all this product 
 
182
        '''
 
183
        
252
184
        if context is None:
253
185
            context = {}
254
186
        invo_obj = self.pool.get('account.invoice')
255
187
        if purchase:
256
 
            [dict[line.product_id.id].append((invo.id, line.price_unit,
257
 
                                              line.price_subtotal,
258
 
                                              line.quantity, line.uos_id and
259
 
                                              line.uos_id.id, invo.date_invoice,
260
 
                                              line.id, line.aux_financial,
261
 
                                              line.aux_qty, invo.cancel_check))
262
 
                for invo in invo_obj.browse(cr, uid, inv_ids, context=context)
263
 
                for line in invo.invoice_line if line and
264
 
                line.product_id and
265
 
                line.product_id.id in dict and
266
 
                type(dict[line.product_id.id]) is list]
267
 
 
 
188
            [dict[line.product_id.id].append((invo.id,line.price_unit,line.price_subtotal,
 
189
                                                      line.quantity, line.uos_id and \
 
190
                                                      line.uos_id.id,invo.date_invoice,line.id,line.aux_financial,line.aux_qty,invo.cancel_check)) \
 
191
                for invo in invo_obj.browse(cr,uid,inv_ids,context=context) for line in invo.invoice_line if line and \
 
192
                line.product_id and \
 
193
                line.product_id.id in dict and \
 
194
                type(dict[line.product_id.id]) is list ]
 
195
            
 
196
        
268
197
        else:
269
 
 
270
 
            [dict[line.product_id.id].append((invo.id, line.price_unit,
271
 
                                              line.price_subtotal, line.quantity,
272
 
                                              line.uos_id and line.uos_id.id,
273
 
                                              invo.date_invoice))
274
 
                for invo in invo_obj.browse(cr, uid, inv_ids, context=context)
275
 
             for line in invo.invoice_line if line and
276
 
                line.product_id and
277
 
                line.product_id.id in dict and
278
 
                type(dict[line.product_id.id]) is list]
279
 
 
 
198
            
 
199
            [dict[line.product_id.id].append((invo.id,line.price_unit,line.price_subtotal, line.quantity, line.uos_id and line.uos_id.id,invo.date_invoice)) \
 
200
                for invo in invo_obj.browse(cr,uid,inv_ids,context=context) for line in invo.invoice_line if line and \
 
201
                line.product_id and \
 
202
                line.product_id.id in dict and \
 
203
                type(dict[line.product_id.id]) is list ]
 
204
        
 
205
        
 
206
        
280
207
        return dict
281
 
 
282
 
    def compute_actual_cost_purchase(self, cr, uid, ids, dic_comp, dic_vent,
283
 
                                    dic_nc_com, dic_nc_vent, context={}):
 
208
        
 
209
    def compute_actual_cost_purchase(self,cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
284
210
        '''
285
211
        Method that performs the actual average cost, receiving the dictionaries of every movement,
286
212
        to perform the calculations for caesarean
296
222
        dat = DateTime()
297
223
        list = []
298
224
        for i in dic_comp:
299
 
            aux.update({i: []})
300
 
            product_brw = product_obj.browse(cr, uid, i, context=context)
 
225
            aux.update({i:[]})
 
226
            product_brw = product_obj.browse(cr,uid,i,context=context)
301
227
            date = False
302
228
            evalu = 'DateTime(a[5]) <= DateTime(aux2[5])'
303
 
            if dic_comp.get(i, False) and len(dic_comp[i]) > 0:
 
229
            if dic_comp.get(i,False) and len(dic_comp[i]) > 0:
304
230
                d = 0
305
231
                gene = (e for e in dic_comp.get(i))
306
 
 
 
232
                
307
233
                while d != len(dic_comp.get(i)):
308
234
                    aux2 = gene.next()
309
 
 
 
235
               
310
236
                    qty = (sum([a[3] for a in dic_comp.get(i) if eval(evalu) ])) - \
311
237
                          (sum([a[3] for a in dic_nc_com.get(i) if eval(evalu)])) + \
312
238
                          (sum([a[0] for a in dic_nc_vent.get(i) if eval(evalu)] )) - \
313
 
                          (sum([a[1] for a in dic_vent.get(
314
 
                              i) if eval(evalu)]))
315
 
 
 
239
                          (sum([a[1] for a in dic_vent.get(i) if eval(evalu) ]))
 
240
                    
316
241
                    price = (sum([a[2] for a in dic_comp.get(i) if eval(evalu) ])) - \
317
242
                            (sum([a[2] for a in dic_nc_com.get(i) if eval(evalu) ])) + \
318
243
                            (sum([a[1] for a in dic_nc_vent.get(i) if eval(evalu) ])) - \
319
 
                            (sum([date and (cost * a[1]) or a[
320
 
                             2] for a in dic_vent.get(i) if eval(evalu)]))
321
 
 
 
244
                            (sum([date and (cost * a[1]) or a[2] for a in dic_vent.get(i) if eval(evalu) ]))
 
245
                    
 
246
                    
322
247
                    if d == 0:
323
 
                        cost = qty > 0 and price/qty
 
248
                        cost = qty > 0 and  price/qty
324
249
                        date = aux2[5]
325
250
                        qty_aux = cost and qty
326
251
                        price_aux = cost and price
327
 
                        aux[i].append((cost, aux2[5], qty))
328
 
                        list.append((cost, aux2[5]))
329
 
                        aux2[6] and invoice_line_obj.write(cr, uid, aux2[6],
330
 
                                                           {'aux_financial': cost*qty,
331
 
                                                            'aux_qty': qty},
332
 
                                                           context=context)
333
 
                        evalu = 'DateTime(a[5]) > DateTime(date) and  \
334
 
                                 DateTime(a[5]) <= DateTime(aux2[5])'
 
252
                        aux[i].append((cost,aux2[5]))
 
253
                        list.append((cost,aux2[5]))
 
254
                        aux2[6] and invoice_line_obj.write(cr,uid,aux2[6],{'aux_financial':cost*qty,'aux_qty':qty},context=context)
 
255
                        evalu = 'DateTime(a[5]) > DateTime(date) and  DateTime(a[5]) <= DateTime(aux2[5])'
335
256
                        d = d + 1
336
 
 
 
257
                        
337
258
                    else:
338
259
                        qty = qty + qty_aux
339
260
                        price = price + price_aux
340
 
                        cost = qty > 0 and price/qty
 
261
                        cost = qty > 0 and  price/qty
341
262
                        date = aux2[5]
342
263
                        qty_aux = cost and qty
343
264
                        price_aux = cost and price
344
 
                        aux[i].append((cost, aux2[5], qty))
345
 
                        list.append((cost, aux2[5]))
346
 
                        aux2[6] and invoice_line_obj.write(cr, uid, aux2[6],
347
 
                                           {'aux_financial': cost*qty,
348
 
                                            'aux_qty': qty}, context=context)
349
 
 
350
 
                        evalu = 'DateTime(a[5]) > DateTime(date) and  \
351
 
                                DateTime(a[5]) <= DateTime(aux2[5])'
352
 
 
 
265
                        aux[i].append((cost,aux2[5]))
 
266
                        list.append((cost,aux2[5]))
 
267
                        aux2[6] and invoice_line_obj.write(cr,uid,aux2[6],{'aux_financial':cost*qty,'aux_qty':qty},context=context)
 
268
                        evalu = 'DateTime(a[5]) > DateTime(date) and  DateTime(a[5]) <= DateTime(aux2[5])'
353
269
                        d = d + 1
354
 
 
 
270
        
355
271
        return aux
356
 
 
357
 
    def list_cost(self, cr, uid, cicle, ids_inv, product_id, company_id, context={}):
 
272
    
 
273
   
 
274
    def list_cost(self,cr,uid,cicle,ids_inv,product_id,company_id,context={}):
358
275
        '''
359
276
        Method that allocates the cost of each sale or note of credit history looking product movement
360
277
        @param cicle Dictionary that contains the ID of the product and its line that generated the movement, to know their numbers and only assign the corresponding cost
365
282
        for d in cicle:
366
283
            invoice_obj = self.pool.get('account.invoice')
367
284
            invoice_line_obj = self.pool.get('account.invoice.line')
368
 
            invo_brw = invoice_obj.browse(cr, uid, d[0], context={})
369
 
            if invo_brw.type == 'out_refund' and \
370
 
               invo_brw.parent_id and invo_brw.parent_id.id in invo_cost:
371
 
                lista.append(
372
 
                    (d[3], d[3] * invo_cost.get(invo_brw.parent_id.id),
373
 
                     invo_cost.get(invo_brw.parent_id.id) or 0, d[4], d[0], d[5]))
374
 
                invoice_line_obj.write(cr, uid, d[6],
375
 
                                       {'aux_financial': invo_cost.get(
376
 
                                        invo_brw.parent_id.id)},
377
 
                                       context=context)
 
285
            invo_brw = invoice_obj.browse(cr,uid,d[0],context={})
 
286
            if invo_brw.type == 'out_refund' and invo_brw.parent_id and invo_brw.parent_id.id in invo_cost:
 
287
                lista.append((d[3], d[3] * invo_cost.get(invo_brw.parent_id.id), invo_cost.get(invo_brw.parent_id.id) or 0, d[4],d[0],d[5] ))
 
288
                invoice_line_obj.write(cr,uid,d[6],{'aux_financial':invo_cost.get(invo_brw.parent_id.id)},context=context)
378
289
                return lista
379
290
 
380
 
            if invo_brw.type == 'out_refund' \
381
 
                    and invo_brw.parent_id and invo_brw.parent_id.id \
382
 
                    not in invo_cost:
383
 
                inv_ids = invoice_obj.search(
384
 
                    cr, uid, [('invoice_line.product_id', '=', product_id),
385
 
                              ('type', '=',
386
 
                               'in_invoice'),
387
 
                              ('company_id',
388
 
                               '=', company_id),
389
 
                                ('date_invoice', '<', invo_brw.parent_id.date_invoice)],
390
 
                                order='date_invoice')
391
 
 
392
 
                inv_ids and [lista.append((d[3],
393
 
                                 line.aux_qty and (d[3] * (
394
 
                                     line.aux_financial/line.aux_qty)),
395
 
                                 line.aux_qty and (
396
 
                                     line.aux_financial/line.aux_qty),
397
 
                                 d[4], d[0], d[5]))
398
 
                 for invo in invoice_obj.browse(cr, uid, [inv_ids[-1]],
399
 
                     context=context)
400
 
                     for line in invo.invoice_line if line and
401
 
                         line.product_id and
402
 
                         line.product_id.id == product_id]
 
291
            if invo_brw.type == 'out_refund' and invo_brw.parent_id and invo_brw.parent_id.id not in invo_cost:
 
292
                inv_ids = invoice_obj.search(cr,uid,[('invoice_line.product_id','=', product_id),
 
293
                                                    ('type','=','in_invoice'),
 
294
                                                    ('company_id','=',company_id),
 
295
                                                    ('date_invoice','<',invo_brw.parent_id.date_invoice)],
 
296
                                                    order='date_invoice')
 
297
                        
 
298
                inv_ids and [lista.append((d[3],(d[3] * (line.aux_financial/line.aux_qty) ) , (line.aux_financial/line.aux_qty), d[4] ,d[0],d[5])) \
 
299
                 for invo in invoice_obj.browse(cr,uid,[inv_ids[-1]],context=context) for line in invo.invoice_line if line and \
 
300
                line.product_id and \
 
301
                line.product_id.id == product_id ]
403
302
                #~ lista and invoice_line_obj.write(cr,uid,d[6],{'aux_financial':lista and lista[2]},context=context)
404
303
                return lista
405
 
 
 
304
            
406
305
            order_date = ids_inv.keys()
407
306
            order_date.sort(reverse=True)
408
307
            for date in order_date:
412
311
                    cost = ids_inv[date]
413
312
                    break
414
313
            try:
415
 
                lista.append((d[0], d[3], d[
416
 
                             3] * cost, cost and cost or 0, d[4], d[5]))
 
314
                lista.append((d[0],d[3], d[3] * cost, cost and cost or 0, d[4],d[5] ))
417
315
                if invo_brw.type == 'out_invoice':
418
 
                    invo_cost.update({d[0]: cost})
 
316
                    invo_cost.update({d[0]:cost})
419
317
            except:
420
318
                pass
421
319
                #~ raise osv.except_osv(_('Invalid action !'),_("Impossible to calculate the actual cost, because the invoice '%s' \
422
320
                                                             #~ does not have a valid date format, to place its cost at \
423
321
                                                            #~ the time of sale ")% (invo_brw.id))
424
322
        return lista
425
 
 
426
 
    def compute_cost(self, cr, uid, ids, context=None, products=False,
427
 
                            period=False, fifo=False, lifo=False, date=False):
 
323
    
 
324
    
 
325
    def compute_cost(self,cr,uid,ids,context=None,products=False,period=False,fifo=False,lifo=False,date=False):
428
326
        '''
429
327
        Method to compute coste from porduct invoice from a wizard or called from other method
430
 
 
 
328
        
431
329
        @param products IDS list of products to compute cost from invoices
432
 
        @param period ids of period to give range to compute cost
433
 
        @param ids ids of wizard for method call
 
330
        @param period ids of period to give range to compute cost 
 
331
        @param ids ids of wizard for method call 
434
332
        @param fifo booblean to compute cost method fifo
435
333
        @param lifo booblean to compute cost method lifo
436
334
        @param date field type date to have a point start
442
340
        global invo_cost
443
341
        cost_obj = self.pool.get('cost.structure')
444
342
        product_obj = self.pool.get('product.product')
445
 
        wz_brw = products or ids and self.browse(
446
 
            cr, uid, ids and ids[0], context=context)
447
 
        product_True = products or wz_brw and hasattr(
448
 
            wz_brw, 'all') and wz_brw.product
449
 
        period_id = products and period or wz_brw and hasattr(
450
 
            wz_brw, 'all') and wz_brw.period_id.id
451
 
        products = products or wz_brw and hasattr(
452
 
            wz_brw, 'all') and wz_brw.product_ids
 
343
        wz_brw = products or ids and self.browse(cr,uid,ids and ids[0],context=context)
 
344
        product_True = products or wz_brw and hasattr(wz_brw, 'all') and wz_brw.product
 
345
        period_id =  products and period or wz_brw and hasattr(wz_brw, 'all') and wz_brw.period_id.id
 
346
        products = products or wz_brw and hasattr(wz_brw, 'all') and wz_brw.product_ids
453
347
        if hasattr(wz_brw, 'all') and wz_brw.all:
454
 
            products = product_obj.search(cr, uid, [], context=context)
455
 
            products = product_obj.browse(cr, uid, products, context=context)
 
348
            products = product_obj.search(cr,uid,[],context=context)
 
349
            products = product_obj.browse(cr,uid,products,context=context)
456
350
        if products and type(products[0]) is int:
457
 
            products = product_obj.browse(cr, uid, products, context=context)
 
351
            products = product_obj.browse(cr,uid,products,context=context)
458
352
        fifo_true = fifo or hasattr(wz_brw, 'fifo') and wz_brw.fifo
459
353
        lifo_true = lifo or hasattr(wz_brw, 'lifo') and wz_brw.lifo
460
 
        company_id = self.pool.get('res.users').browse(
461
 
            cr, uid, [uid], context=context)[0].company_id.id
 
354
        company_id = self.pool.get('res.users').browse(cr,uid,[uid],context=context)[0].company_id.id
462
355
        if product_True or hasattr(wz_brw, 'all') and wz_brw.all:
463
356
            dic_comp = {}
464
357
            dic_vent = {}
467
360
            dic_nc_com = {}
468
361
            dic_nc_vent = {}
469
362
            aux_cancel = False
470
 
            [(dic_comp.update({i.id: []}), dic_vent.update({i.id: []}),
471
 
              dic_nc_com.update({i.id: []}), aux_dic_vent.update({i.id: []}),
472
 
              aux_dic_nc_vent.update({i.id: []}), dic_nc_vent.update({i.id: []})) for i in products]
473
 
 
474
 
            product_brw = product_obj.browse(
475
 
                cr, uid, dic_comp.keys(), context=context)
 
363
            [(dic_comp.update({i.id:[]}),dic_vent.update({i.id:[]})   , dic_nc_com.update({i.id:[]})    ,aux_dic_vent.update({i.id:[]})    ,aux_dic_nc_vent.update({i.id:[]})    , dic_nc_vent.update({i.id:[]})) for i in products]
 
364
            product_brw = product_obj.browse(cr,uid,dic_comp.keys(),context=context)
476
365
            date_aux = [i.date_cost_ult for i in product_brw if i.cost_ult > 0]
477
366
            date_aux.sort(reverse=True)
478
 
            products_date = date_aux and date \
479
 
                            and DateTime(date) < DateTime(date_aux[-1]) \
480
 
                            and [date] or date_aux \
481
 
                            and DateTime(date_aux[-1]) < DateTime(date) \
482
 
                            and [date_aux[-1]] or [date]
 
367
            products_date = date_aux and date and DateTime(date) < DateTime(date_aux[-1]) and [date] or date_aux and DateTime(date_aux[-1]) < DateTime(date) and [date_aux[-1]] or [date]
483
368
            products_date.sort(reverse=True)
484
369
            #~  Select quantity and cost of product from supplier invoice
485
370
            if not context.get('invoice_cancel'):
486
 
                [dic_comp[i.id].append((False, i.cost_ult,
487
 
                                       (i.cost_ult * i.qty_ult),
488
 
                                       i.qty_ult, i.ult_om and
489
 
                                       i.ult_om.id, i.date_cost_ult, False, 0, 0))
490
 
                    for i in product_brw if i.cost_ult > 0
491
 
                    and DateTime(products_date[-1]) >= DateTime(i.date_cost_ult)]
492
 
 
493
 
            #~ -------------------------- Search invoices with products selecte
494
 
            invo_com_ids = self.search_invoice(cr, uid, ids, dic_comp,
495
 
                                               'in_invoice', period_id,
496
 
                                               company_id, products_date
497
 
                                               and products_date[0]
498
 
                                               or False, context=context)
499
 
 
500
 
            invo_ven_ids = self.search_invoice(cr, uid, ids, dic_vent,
501
 
                                               'out_invoice', period_id,
502
 
                                               company_id, products_date
503
 
                                               and products_date[0]
504
 
                                               or False, context=context)
505
 
 
506
 
            invo_nc_com_ids = self.search_invoice(cr, uid, ids, dic_nc_com,
507
 
                                                  'in_refund', period_id,
508
 
                                                  company_id, products_date
509
 
                                                  and products_date[0]
510
 
                                                  or False, context=context)
511
 
 
512
 
            invo_nc_ven_ids = self.search_invoice(cr, uid, ids, dic_nc_vent,
513
 
                                                  'out_refund', period_id,
514
 
                                                  company_id, products_date
515
 
                                                  and products_date[0]
516
 
                                                  or False, context=context)
517
 
 
518
 
            #~ -------------  Generate a dict with line values of invoices by p
519
 
 
520
 
            dic_comp =  invo_com_ids and \
521
 
                        self.update_dictionary(cr, uid, ids, dic_comp,
522
 
                                               invo_com_ids, True,
523
 
                                               context=context) or dic_comp
524
 
 
525
 
            dic_vent = invo_ven_ids and \
526
 
                       self.update_dictionary(cr, uid, ids, dic_vent,
527
 
                               invo_ven_ids, False, context=context) or dic_vent
528
 
 
529
 
            aux_dic_vent = invo_ven_ids and \
530
 
                           self.update_dictionary(cr, uid, ids, aux_dic_vent,
531
 
                            invo_ven_ids, False, context=context) or aux_dic_vent
532
 
 
533
 
            dic_nc_com = invo_nc_com_ids and \
534
 
                         self.update_dictionary(cr, uid, ids, dic_nc_com,
535
 
                           invo_nc_com_ids, False, context=context) or dic_nc_com
536
 
 
537
 
            dic_nc_vent = invo_nc_ven_ids and \
538
 
                          self.update_dictionary(cr, uid, ids, dic_nc_vent,
539
 
                           invo_nc_ven_ids, True, context=context) or dic_nc_vent
540
 
 
541
 
            aux_dic_nc_vent = invo_nc_ven_ids and \
542
 
                              self.update_dictionary(cr, uid, ids,
543
 
                                      aux_dic_nc_vent, invo_nc_ven_ids,
544
 
                                       True, context=context) or aux_dic_nc_vent
545
 
 
546
 
            for i in dic_comp:  # Ciclo por cada uno de los productos
547
 
                if dic_comp.get(i, False):  # Validar valores en la compras
548
 
                    ids_inv = {}
 
371
                [dic_comp[i.id].append((False,i.cost_ult,(i.cost_ult * i.qty_ult ), i.qty_ult, i.ult_om and i.ult_om.id,i.date_cost_ult,False,0,0 )) \
 
372
                    for i in product_brw if i.cost_ult > 0 and DateTime(products_date[-1]) >= DateTime(i.date_cost_ult) ]
 
373
            
 
374
            
 
375
            #~ -------------------------- Search invoices with products selected --------------------------------
 
376
            invo_com_ids = self.search_invoice(cr,uid,ids,dic_comp,'in_invoice',period_id,company_id,products_date and products_date[0] or False,context=context)
 
377
       
 
378
            
 
379
            invo_ven_ids = self.search_invoice(cr,uid,ids,dic_vent,'out_invoice',period_id,company_id,products_date and products_date[0] or False,context=context)
 
380
       
 
381
            
 
382
            invo_nc_com_ids = self.search_invoice(cr,uid,ids,dic_nc_com,'in_refund',period_id,company_id,products_date and products_date[0] or False,context=context)
 
383
       
 
384
            
 
385
            invo_nc_ven_ids = self.search_invoice(cr,uid,ids,dic_nc_vent,'out_refund',period_id,company_id,products_date and products_date[0] or False,context=context)
 
386
           
 
387
            #~ -------------  Generate a dict with line values of invoices by product -------------------------
 
388
                
 
389
            dic_comp =  invo_com_ids and self.update_dictionary(cr,uid,ids,dic_comp,invo_com_ids,True,context=context) or dic_comp
 
390
                
 
391
            dic_vent = invo_ven_ids and self.update_dictionary(cr,uid,ids,dic_vent,invo_ven_ids,False,context=context) or dic_vent
 
392
            aux_dic_vent = invo_ven_ids and self.update_dictionary(cr,uid,ids,aux_dic_vent,invo_ven_ids,False,context=context) or aux_dic_vent
 
393
                
 
394
                
 
395
            dic_nc_com = invo_nc_com_ids and self.update_dictionary(cr,uid,ids,dic_nc_com,invo_nc_com_ids,False,context=context) or dic_nc_com
 
396
            
 
397
        
 
398
            dic_nc_vent = invo_nc_ven_ids and self.update_dictionary(cr,uid,ids,dic_nc_vent,invo_nc_ven_ids,True,context=context) or dic_nc_vent
 
399
            aux_dic_nc_vent = invo_nc_ven_ids and self.update_dictionary(cr,uid,ids,aux_dic_nc_vent,invo_nc_ven_ids,True,context=context) or aux_dic_nc_vent
 
400
                
 
401
            for i in dic_comp:
 
402
                if dic_comp.get(i,False) and len(dic_comp[i]) > 0:
 
403
                    ids_inv = {} 
549
404
                    if context.get('invoice_cancel'):
550
 
                        dic_comp[i] and dic_comp[i][0] \
551
 
                                and (dic_comp[i][0][7] - dic_comp[i][0][2]) >= 0 and \
552
 
                                dic_comp[i].insert(0, (False,
553
 
                                ((dic_comp[i][0][7] - dic_comp[i][0][2]) /
554
 
                                ((dic_comp[i][0][8] - dic_comp[i][0][3]) > 0
555
 
                                and (
556
 
                                    dic_comp[
557
 
                                        i][0][8] - dic_comp[i][0][3]) or 1)),
558
 
                                 (dic_comp[i][0][7] - dic_comp[i][0][2]),
559
 
                                 (dic_comp[i][0][8] - dic_comp[i][0][3]),
560
 
                                  dic_comp[i][0][4], dic_comp[i][0][5], False, 0, 0))
561
 
 
562
 
                        len(dic_comp[i]) > 1 and  \
563
 
                                invo_line_obj.write(
564
 
                                    cr, uid, [dic_comp[i][1][6]],
565
 
                               {'aux_financial': (dic_comp[i][1][7] - dic_comp[i][1][2]),
566
 
                                'aux_qty': (dic_comp[i][1][8] - dic_comp[i][1][3])},
567
 
                                 context=context)
568
 
 
569
 
                        print "dic_comp[i]", dic_comp[i]
570
 
                        len(dic_comp[
571
 
                            i]) > 1 and invo_obj.write(
572
 
                                cr, uid, [dic_comp[i][1][0]],
573
 
                                        {'cancel_check': True}, context=context) or invo_obj.write(cr, uid, [dic_comp[i][0][0]],
574
 
                                        {'cancel_check': True}, context=context)
575
 
                        len(dic_comp[i]) > 1 and dic_comp[i].pop(
576
 
                            1)  # Grabo en la factura que ya fue cancelada
577
 
 
 
405
                        dic_comp[i] and dic_comp[i][0] and (dic_comp[i][0][7] - dic_comp[i][0][2]) >= 0 and dic_comp[i].insert(0,(False,
 
406
                                    ( (dic_comp[i][0][7] - dic_comp[i][0][2] )/ ( (dic_comp[i][0][8] - dic_comp[i][0][3]) > 0 and (dic_comp[i][0][8] - dic_comp[i][0][3]) or 1)   )   ,
 
407
                                     (dic_comp[i][0][7] - dic_comp[i][0][2]),
 
408
                                     (dic_comp[i][0][8] - dic_comp[i][0][3]) , 
 
409
                                      dic_comp[i][0][4] , dic_comp[i][0][5],False, 0, 0  ))
 
410
                        
 
411
                        len(dic_comp[i]) > 1 and  invo_line_obj.write(cr,uid,[dic_comp[i][1][6]],{'aux_financial':(dic_comp[i][1][7] - dic_comp[i][1][2]),'aux_qty':(dic_comp[i][1][8] - dic_comp[i][1][3])},context=context)
 
412
                        invo_obj.write(cr,uid,[dic_comp[i][1][0]],{'cancel_check':True},context=context)
 
413
                        dic_comp[i] and dic_comp[i][0] and dic_comp[i].pop(1)
 
414
 
 
415
                    
 
416
                    
578
417
                    dic_comp[i][0][0] is not False and dic_comp[i][0][9] and dic_comp[i][0][7] > 0 and \
579
 
                    dic_comp[i].insert(
580
 
                        0, (False, (dic_comp[
581
 
                            i][0][7]/dic_comp[i][0][8]), dic_comp[i][0][7], dic_comp[i][0][8], dic_comp[i][0][4],
582
 
                                          dic_comp[i][0][5], 0.0, 0.0))  # Inserto en la lista de la compra el calculo del costo anterior porque la factura fue cancelada
583
 
 
 
418
                    dic_comp[i].insert(0,(False,(dic_comp[i][0][7]/dic_comp[i][0][8]),dic_comp[i][0][7],dic_comp[i][0][8],dic_comp[i][0][4],
 
419
                                          dic_comp[i][0][5],0.0,0.0  ))
 
420
                    
584
421
                    if dic_comp[i][0][0] is not False and not dic_comp[i][0][9] and dic_comp[i][0][7] <= 0:
585
 
                        inv_ids = invo_obj.search(
586
 
                            cr, uid, [('invoice_line.product_id', '=', i),
587
 
                                                    ('type', '=',
588
 
                                                     'in_invoice'),
589
 
                                                    ('company_id',
590
 
                                                     '=', company_id),
591
 
                                                    ('date_invoice', '<', dic_comp[i][0][5])],
 
422
                        inv_ids = invo_obj.search(cr,uid,[('invoice_line.product_id','=', i),
 
423
                                                    ('type','=','in_invoice'),
 
424
                                                    ('company_id','=',company_id),
 
425
                                                    ('date_invoice','<',dic_comp[i][0][5])],
592
426
                                                    order='date_invoice')
593
 
                        inv_ids and [dic_comp[i].insert(
594
 
                            0, (invo.id, line.aux_qty and (line.aux_financial/line.aux_qty), line.aux_financial,
595
 
                                                      line.aux_qty, line.uos_id and
596
 
                                                      line.uos_id.id, invo.date_invoice, line.id, line.aux_financial, line.aux_qty, invo.cancel_check))
597
 
 
598
 
                for invo in invo_obj.browse(cr, uid, [inv_ids[-1]], context=context) for line in invo.invoice_line if line and
599
 
                line.product_id and
600
 
                line.product_id.id == i]
601
 
 
602
 
                    [ids_inv.update({h[5]:h[1]}) for h in dic_comp[i]]
603
 
 
604
 
                    if dic_vent.get(i, False) and len(dic_vent.get(i, [])) > 0:
605
 
                        lista = self.list_cost(cr, uid, dic_vent.get(
606
 
                            i), ids_inv, i, company_id)
607
 
                        dic_vent.update({i: lista})
608
 
 
609
 
                    if dic_nc_vent.get(i, False) and len(dic_nc_vent.get(i, [])) > 0:
610
 
                        lista = self.list_cost(cr, uid, dic_nc_vent.get(
611
 
                            i), ids_inv, i, company_id)
612
 
                        dic_nc_vent.update({i: lista})
613
 
 
 
427
                        inv_ids and [dic_comp[i].insert(0,(invo.id,(line.aux_financial/line.aux_qty),line.aux_financial,
 
428
                                                      line.aux_qty, line.uos_id and \
 
429
                                                      line.uos_id.id,invo.date_invoice,line.id,line.aux_financial,line.aux_qty,invo.cancel_check)) \
 
430
                
 
431
                for invo in invo_obj.browse(cr,uid,[inv_ids[-1]],context=context) for line in invo.invoice_line if line and \
 
432
                line.product_id and \
 
433
                line.product_id.id == i ]
 
434
                        
 
435
                    [ ids_inv.update({h[5]:h[1]}) for h in dic_comp[i]]
 
436
                    
 
437
                    if dic_vent.get(i,False) and len(dic_vent.get(i,[])) > 0 :
 
438
                        lista = self.list_cost(cr,uid,dic_vent.get(i),ids_inv,i,company_id)
 
439
                        dic_vent.update({i:lista})
 
440
                    
 
441
                    if dic_nc_vent.get(i,False) and len(dic_nc_vent.get(i,[])) > 0 :
 
442
                        lista = self.list_cost(cr,uid,dic_nc_vent.get(i),ids_inv,i,company_id)
 
443
                        dic_nc_vent.update({i:lista}) 
 
444
                        
614
445
            invo_cost = {}
615
446
            if fifo_true or lifo_true:
616
 
                fifo = self.compute_cost_fifo(cr, uid, dic_comp, dic_vent,
617
 
                                              dic_nc_com, dic_nc_vent)
618
 
 
619
 
            cost_acc = self.compute_actual_cost_purchase(cr, uid, ids,
620
 
                                                         dic_comp, dic_vent,
621
 
                                                         dic_nc_com, dic_nc_vent)
622
 
 
 
447
                fifo = self.compute_cost_fifo(cr,uid,dic_comp,dic_vent,dic_nc_com,dic_nc_vent)
 
448
            
 
449
            cost_acc = self.compute_actual_cost_purchase(cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent)
 
450
            
623
451
            for i in dic_comp:
624
452
                ids_inv = {}
625
453
                [ids_inv.update({h[1]:h[0]}) for h in cost_acc[i]]
626
 
                if aux_dic_vent.get(i, False) and len(aux_dic_vent.get(i, [])) > 0:
627
 
                        lista = self.list_cost(cr, uid, aux_dic_vent.get(
628
 
                            i), ids_inv, i, company_id)
629
 
                        aux_dic_vent.update({i: lista})
630
 
 
631
 
                if aux_dic_nc_vent.get(i, False) and len(aux_dic_nc_vent.get(i, [])) > 0:
632
 
                    lista = self.list_cost(cr, uid, aux_dic_nc_vent.get(
633
 
                        i), ids_inv, i, company_id)
634
 
                    aux_dic_nc_vent.update({i: lista})
635
 
 
636
 
            cost = self.compute_actual_cost(cr, uid, ids, dic_comp,
637
 
                                            aux_dic_vent, dic_nc_com,
638
 
                                            aux_dic_nc_vent)
639
 
        return (cost, cost_acc)
 
454
                if aux_dic_vent.get(i,False) and len(aux_dic_vent.get(i,[])) > 0 :
 
455
                        lista = self.list_cost(cr,uid,aux_dic_vent.get(i),ids_inv,i,company_id)
 
456
                        aux_dic_vent.update({i:lista})
 
457
                    
 
458
                if aux_dic_nc_vent.get(i,False) and len(aux_dic_nc_vent.get(i,[])) > 0 :
 
459
                    lista = self.list_cost(cr,uid,aux_dic_nc_vent.get(i),ids_inv,i,company_id)
 
460
                    aux_dic_nc_vent.update({i:lista}) 
 
461
            
 
462
            print "cost_acc",cost_acc 
 
463
            cost = self.compute_actual_cost(cr,uid,ids,dic_comp,aux_dic_vent,dic_nc_com,aux_dic_nc_vent)
 
464
            print "cost",cost
 
465
        return (cost,cost_acc)
 
466
 
 
467
compute_cost()
640
468