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
##########################################################################
26
from openerp.osv import osv, fields
27
import openerp.tools as tools
28
from openerp.tools.translate import _
24
################################################################################
26
from osv import fields, osv
28
from tools.translate import _
30
29
from tools import config
31
import openerp.netsvc as netsvc
32
31
import decimal_precision as dp
33
32
from DateTime import DateTime
39
class compute_cost(osv.TransientModel):
37
class compute_cost(osv.osv_memory):
41
40
_name = 'compute.cost'
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"),
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"),
66
def compute_cost_fifo(self, cr, uid, dic_comp, dic_vent, dic_nc_com, dic_nc_vent, context={}):
56
def compute_cost_fifo(self,cr,uid,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
68
58
Method that performs the actual FIFO cost, receiving the dictionaries of every movement,
69
59
to perform the calculations for caesarean
112
93
cont_qty = cont + cont_qty
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:
120
cost = price / (cont_qty > 0 and cont_qty or cont > 0 and cont)
100
cost = price / (cont_qty > 0 and cont_qty or cont > 0 and cont)
123
def search_invoice(self, cr, uid, ids, dict, type, period, company, date,
103
def search_invoice(self,cr,uid,ids,dict,type,period,company,date,context=None):
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),
129
108
if context is None:
131
110
invo_obj = self.pool.get('account.invoice')
133
invo_ids = invo_obj.search(
135
'invoice_line.product_id', 'in', tuple(dict.keys())),
139
('date_invoice', '>=', date)],
140
order='date_invoice')
112
invo_ids = invo_obj.search(cr,uid,[('invoice_line.product_id','in', tuple(dict.keys())),
114
('company_id','=',company),
115
('date_invoice','>=',date)],
116
order='date_invoice')
143
invo_ids = invo_obj.search(
145
'invoice_line.product_id', 'in', tuple(dict.keys())),
149
('company_id', '=', company)],
150
order='date_invoice')
119
invo_ids = invo_obj.search(cr,uid,[('invoice_line.product_id','in', tuple(dict.keys())),
121
('state','in',('open','paid')),
122
('company_id','=',company)],
123
order='date_invoice')
153
def compute_actual_cost(self, cr, uid, ids, dic_comp, dic_vent, dic_nc_com,
154
dic_nc_vent, context={}):
126
def compute_actual_cost(self,cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
156
128
Method that performs the actual average cost, receiving the dictionaries of every movement,
157
129
to perform the calculations for caesarean
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)]))
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(
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')
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')
167
if context.get('not_write',False):
208
if context.get('invoice_cancel', False):
209
product_obj.write(cr, uid, [product_brw.id],
211
'date_cost_ult': date,
212
'qty_ult': aux.get(i)
214
'ult_om': aux.get(i)[-1] or [],
215
'date_ult_om': date},
218
if product_brw.property_cost_structure and\
219
product_brw.cost_ult > 0:
220
product_obj.write(cr, uid, [product_brw.id],
222
'date_cost_ult': date,
223
'qty_ult': aux.get(i)
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 [],
230
'ant_om': product_brw.ult_om
231
and product_brw.ult_om.id
233
'date_ant_om': product_brw.date_ult_om},
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)
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)
236
product_obj.write(cr, uid, [product_brw.id],
238
'date_cost_ult': date,
239
'qty_ult': aux.get(i)
241
'ult_om': aux.get(i)[-1] or [],
242
'date_ult_om': date},
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)
246
def update_dictionary(self, cr, uid, ids, dict, inv_ids, purchase,
249
Update a dict send with move all this product
179
def update_dictionary(self,cr,uid,ids,dict,inv_ids,purchase,context=None):
181
Update a dict send with move all this product
252
184
if context is None:
254
186
invo_obj = self.pool.get('account.invoice')
256
[dict[line.product_id.id].append((invo.id, line.price_unit,
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
265
line.product_id.id in dict and
266
type(dict[line.product_id.id]) is list]
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 ]
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,
274
for invo in invo_obj.browse(cr, uid, inv_ids, context=context)
275
for line in invo.invoice_line if line and
277
line.product_id.id in dict and
278
type(dict[line.product_id.id]) is list]
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 ]
282
def compute_actual_cost_purchase(self, cr, uid, ids, dic_comp, dic_vent,
283
dic_nc_com, dic_nc_vent, context={}):
209
def compute_actual_cost_purchase(self,cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent,context={}):
285
211
Method that performs the actual average cost, receiving the dictionaries of every movement,
286
212
to perform the calculations for caesarean
298
224
for i in dic_comp:
300
product_brw = product_obj.browse(cr, uid, i, context=context)
226
product_brw = product_obj.browse(cr,uid,i,context=context)
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:
305
231
gene = (e for e in dic_comp.get(i))
307
233
while d != len(dic_comp.get(i)):
308
234
aux2 = gene.next()
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(
239
(sum([a[1] for a in dic_vent.get(i) if eval(evalu) ]))
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)]))
244
(sum([date and (cost * a[1]) or a[2] for a in dic_vent.get(i) if eval(evalu) ]))
323
cost = qty > 0 and price/qty
248
cost = qty > 0 and price/qty
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,
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])'
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
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)
350
evalu = 'DateTime(a[5]) > DateTime(date) and \
351
DateTime(a[5]) <= DateTime(aux2[5])'
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])'
357
def list_cost(self, cr, uid, cicle, ids_inv, product_id, company_id, context={}):
274
def list_cost(self,cr,uid,cicle,ids_inv,product_id,company_id,context={}):
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
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:
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)},
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)
380
if invo_brw.type == 'out_refund' \
381
and invo_brw.parent_id and invo_brw.parent_id.id \
383
inv_ids = invoice_obj.search(
384
cr, uid, [('invoice_line.product_id', '=', product_id),
389
('date_invoice', '<', invo_brw.parent_id.date_invoice)],
390
order='date_invoice')
392
inv_ids and [lista.append((d[3],
393
line.aux_qty and (d[3] * (
394
line.aux_financial/line.aux_qty)),
396
line.aux_financial/line.aux_qty),
398
for invo in invoice_obj.browse(cr, uid, [inv_ids[-1]],
400
for line in invo.invoice_line if line 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')
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)
406
305
order_date = ids_inv.keys()
407
306
order_date.sort(reverse=True)
408
307
for date in order_date:
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]
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)]
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
498
or False, context=context)
500
invo_ven_ids = self.search_invoice(cr, uid, ids, dic_vent,
501
'out_invoice', period_id,
502
company_id, products_date
504
or False, context=context)
506
invo_nc_com_ids = self.search_invoice(cr, uid, ids, dic_nc_com,
507
'in_refund', period_id,
508
company_id, products_date
510
or False, context=context)
512
invo_nc_ven_ids = self.search_invoice(cr, uid, ids, dic_nc_vent,
513
'out_refund', period_id,
514
company_id, products_date
516
or False, context=context)
518
#~ ------------- Generate a dict with line values of invoices by p
520
dic_comp = invo_com_ids and \
521
self.update_dictionary(cr, uid, ids, dic_comp,
523
context=context) or dic_comp
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
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
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
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
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
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
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) ]
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)
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)
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)
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)
387
#~ ------------- Generate a dict with line values of invoices by product -------------------------
389
dic_comp = invo_com_ids and self.update_dictionary(cr,uid,ids,dic_comp,invo_com_ids,True,context=context) or dic_comp
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
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
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
402
if dic_comp.get(i,False) and len(dic_comp[i]) > 0:
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
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))
562
len(dic_comp[i]) > 1 and \
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])},
569
print "dic_comp[i]", dic_comp[i]
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
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 ))
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)
578
417
dic_comp[i][0][0] is not False and dic_comp[i][0][9] and dic_comp[i][0][7] > 0 and \
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
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 ))
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),
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))
598
for invo in invo_obj.browse(cr, uid, [inv_ids[-1]], context=context) for line in invo.invoice_line if line and
600
line.product_id.id == i]
602
[ids_inv.update({h[5]:h[1]}) for h in dic_comp[i]]
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})
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})
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)) \
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 ]
435
[ ids_inv.update({h[5]:h[1]}) for h in dic_comp[i]]
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})
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})
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)
619
cost_acc = self.compute_actual_cost_purchase(cr, uid, ids,
621
dic_nc_com, dic_nc_vent)
447
fifo = self.compute_cost_fifo(cr,uid,dic_comp,dic_vent,dic_nc_com,dic_nc_vent)
449
cost_acc = self.compute_actual_cost_purchase(cr,uid,ids,dic_comp,dic_vent,dic_nc_com,dic_nc_vent)
623
451
for i in dic_comp:
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})
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})
636
cost = self.compute_actual_cost(cr, uid, ids, dic_comp,
637
aux_dic_vent, dic_nc_com,
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})
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})
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)
465
return (cost,cost_acc)