Merge lp:~sandi-dirntis/openerpsl/openerpsl_20140424_1 into lp:openerpsl/7.0

Proposed by Aleksander Dirntiš
Status: Merged
Merged at revision: 393
Proposed branch: lp:~sandi-dirntis/openerpsl/openerpsl_20140424_1
Merge into: lp:openerpsl/7.0
Diff against target: 142 lines (+64/-57)
2 files modified
purchase_recalculation/product_product.py (+64/-54)
purchase_recalculation/wizard/account_product_cost_recalculation.py (+0/-3)
To merge this branch: bzr merge lp:~sandi-dirntis/openerpsl/openerpsl_20140424_1
Reviewer Review Type Date Requested Status
Mentis Pending
Review via email: mp+216985@code.launchpad.net

Description of the change

[FIX] purchase_recalculation: bug fixes

To post a comment you must log in.
393. By Aleksander Dirntiš

[FIX] purchase_recalculation: bug fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase_recalculation/product_product.py'
2--- purchase_recalculation/product_product.py 2014-04-23 11:51:50 +0000
3+++ purchase_recalculation/product_product.py 2014-04-24 07:33:19 +0000
4@@ -69,60 +69,70 @@
5 _period = False
6 _date_from = dates.get('date_from', False)
7 _date_to = dates.get('date_to', False)
8- _location_ids = self.pool.get('stock.location').search(cr, uid, [('usage','=','supplier')])
9- if _date_from and _date_to:
10- _sql_string = ' SELECT sm.id \n' \
11- ' FROM stock_move AS sm \n' \
12- ' WHERE sm.product_id = {product} \n' \
13- ' AND sm.date < \'{date_to}\' \n' \
14- ' AND sm.state = \'done\' \n' \
15- ' AND sm.location_id NOT IN {locations} \n' \
16- ' AND sm.location_dest_id NOT IN {locations} \n' \
17- 'ORDER BY sm.date DESC \n' \
18- ' LIMIT 1;'.format(product = ids[0],
19- date_to = _date_to,
20- locations = tuple(_location_ids)).replace(',)', ')')
21- cr.execute(_sql_string)
22- _last_out_move_tups = cr.fetchall()
23- _last_out_move_id = []
24- for _tup in _last_out_move_tups:
25- _last_out_move_id.append(_tup[0])
26-
27- if len(_last_out_move_id) == 1:
28- _last_out_move = self.pool.get('stock.move').browse(cr, uid, _last_out_move_id[0], context)
29- _period_id = self.pool.get('account.period').find(cr, uid, _last_out_move.date, context)
30- _period = self.pool.get('account.period').browse(cr, uid, _period_id[0], context)
31- _cost = _last_out_move.price_unit
32-
33- _sql_string = ' SELECT sm.id \n' \
34- ' FROM stock_move AS sm \n' \
35- ' WHERE sm.product_id = {product} \n' \
36- ' AND sm.date < \'{date_to}\' \n' \
37- ' AND sm.state = \'done\' \n' \
38- 'ORDER BY sm.date;'.format(product = ids[0],
39- date_from = _date_from,
40- date_to = _date_to).replace(',)', ')')
41-
42-
43- cr.execute(_sql_string)
44- _move_tups = cr.fetchall()
45- _move_ids = []
46- for _tup in _move_tups:
47- _move_ids.append(_tup[0])
48-
49- _moves = self.pool.get('stock.move').browse(cr, uid, _move_ids, context)
50- for _move in _moves:
51- if _move.location_id.usage != 'internal' and _move.location_dest_id.usage == 'internal':
52- _stock = _stock + _move.product_qty
53- elif _move.location_id.usage == 'internal' and _move.location_dest_id.usage != 'internal':
54- _stock = _stock - _move.product_qty
55-
56- if _stock == 0.0:
57- _cost = 0.0
58- _period = False
59- else:
60- _cost = _cost * _stock
61-
62+
63+ # izračunam zalogo na začetku obdobja
64+ _sql_string = ' SELECT sm.id \n' \
65+ ' FROM stock_move AS sm \n' \
66+ ' WHERE sm.product_id = {product} \n' \
67+ ' AND sm.date < \'{date_to}\' \n' \
68+ ' AND sm.state = \'done\' \n' \
69+ 'ORDER BY sm.date;'.format(product = ids[0],
70+ date_from = _date_from,
71+ date_to = _date_to).replace(',)', ')')
72+
73+
74+ cr.execute(_sql_string)
75+ _move_tups = cr.fetchall()
76+ _move_ids = []
77+ for _tup in _move_tups:
78+ _move_ids.append(_tup[0])
79+
80+ _moves = self.pool.get('stock.move').browse(cr, uid, _move_ids, context)
81+ for _move in _moves:
82+ if _move.location_id.usage != 'internal' and _move.location_dest_id.usage == 'internal':
83+ _stock = _stock + _move.product_qty
84+ elif _move.location_id.usage == 'internal' and _move.location_dest_id.usage != 'internal':
85+ _stock = _stock - _move.product_qty
86+ _stock = round(_stock, digits['quantity'])
87+
88+ # če je zaloga na zečetku obdobja 0 vrnem same nule
89+ if _stock == round(0.0, digits['quantity']):
90+ return [round(_stock, digits['quantity']), round(_cost, digits['price']), _period]
91+
92+ # najdem zadnjo prodajo
93+ _int_location_ids = self.pool.get('stock.location').search(cr, uid, [('usage','=','internal')])
94+ _sup_location_ids = self.pool.get('stock.location').search(cr, uid, [('usage','=','supplier')])
95+ _last_out_move_id = self.pool.get('stock.move').search(cr, uid, [('product_id','=',ids[0]),
96+ ('date','<',_date_to),
97+ ('location_id','in',_int_location_ids),
98+ ('location_dest_id','not in',_sup_location_ids)],
99+ order='date desc',
100+ limit=1)
101+
102+ # če obstaja zadnja prodaja vzamem ceno iz stock_move-a
103+ if len(_last_out_move_id) == 1:
104+ _last_out_move = self.pool.get('stock.move').browse(cr, uid, _last_out_move_id[0], context)
105+ _period_id = self.pool.get('account.period').find(cr, uid, _last_out_move.date, context)
106+ _period = self.pool.get('account.period').browse(cr, uid, _period_id[0], context)
107+ _cost = round(_last_out_move.price_unit, digits['price']) * _stock
108+ return [round(_stock, digits['quantity']), round(_cost, digits['price']), _period]
109+
110+ # če ni prodaje najdem zadnjo nabavo
111+ _last_in_move_id = self.pool.get('stock.move').search(cr, uid, [('product_id','=',ids[0]),
112+ ('date','<',_date_to),
113+ ('location_id','in',_sup_location_ids),
114+ ('location_dest_id','in',_int_location_ids)],
115+ order='date desc',
116+ limit=1)
117+ # če obstaja zadnja prodaja vzamem ceno iz stock_move-a
118+ if len(_last_in_move_id) == 1:
119+ _last_in_move = self.pool.get('stock.move').browse(cr, uid, _last_in_move_id[0], context)
120+ _period_id = self.pool.get('account.period').find(cr, uid, _last_in_move.date, context)
121+ _period = self.pool.get('account.period').browse(cr, uid, _period_id[0], context)
122+ _cost = round(_last_in_move.price_unit, digits['price']) * _stock
123+ return [round(_stock, digits['quantity']), round(_cost, digits['price']), _period]
124+
125+ # če ni niti zadnje prodaje niti zadnje zaloge vrnem 0
126 return [round(_stock, digits['quantity']), round(_cost, digits['price']), _period]
127
128 def _get_purchase_amount_and_cost(self, cr, uid, ids, dates, digits, context):
129
130=== modified file 'purchase_recalculation/wizard/account_product_cost_recalculation.py'
131--- purchase_recalculation/wizard/account_product_cost_recalculation.py 2014-04-23 11:51:50 +0000
132+++ purchase_recalculation/wizard/account_product_cost_recalculation.py 2014-04-24 07:33:19 +0000
133@@ -126,9 +126,6 @@
134
135 # zapišem povprečno ceno v tabelo
136 if _average_cost and _average_cost <> 0:
137- _dates['date_from'] = _date_from + ' 00:00:00'
138- _dates['date_to'] = _date_to + ' 23:59:59'
139-
140 _product_cost_id = self.pool.get('product.period.cost').search(cr, uid, [('product_id','=', _product.id),
141 ('period_id','=',_period.id)])
142 if len(_product_cost_id) <> 0:

Subscribers

People subscribed via source and target branches