Merge lp:~sandi-dirntis/openerpsl/openerpsl_20140423_1 into lp:openerpsl/7.0
- openerpsl_20140423_1
- Merge into 7.0
Proposed by
Aleksander Dirntiš
Status: | Merged |
---|---|
Merged at revision: | 392 |
Proposed branch: | lp:~sandi-dirntis/openerpsl/openerpsl_20140423_1 |
Merge into: | lp:openerpsl/7.0 |
Diff against target: |
190 lines (+40/-39) 3 files modified
purchase_recalculation/product_product.py (+7/-9) purchase_recalculation/wizard/account_product_cost_recalculation.py (+23/-23) purchase_recalculation/wizard/account_product_cost_set.py (+10/-7) |
To merge this branch: | bzr merge lp:~sandi-dirntis/openerpsl/openerpsl_20140423_1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mentis | Pending | ||
Review via email: mp+216867@code.launchpad.net |
Commit message
Description of the change
[FIX] purchase_
To post a comment you must log in.
- 392. 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-22 07:13:07 +0000 |
3 | +++ purchase_recalculation/product_product.py 2014-04-23 11:51:12 +0000 |
4 | @@ -29,7 +29,7 @@ |
5 | class product_product(osv.Model): |
6 | _inherit="product.product" |
7 | |
8 | - def _get_stock_and_cost_inventory(self, cr, uid, ids, dates, digits, context): |
9 | + def _get_inventory_stock_and_cost(self, cr, uid, ids, dates, digits, context): |
10 | if dates is None: |
11 | dates = {} |
12 | _stock = 0.0 |
13 | @@ -61,7 +61,7 @@ |
14 | _cost = _acc_move_line.debit + _acc_move_line.credit |
15 | return [round(_stock, digits['quantity']) , round(_cost, digits['price'])] |
16 | |
17 | - def _get_stock_and_cost(self, cr, uid, ids, dates, digits, context): |
18 | + def _get_start_stock_and_cost(self, cr, uid, ids, dates, digits, context): |
19 | if dates is None: |
20 | dates = {} |
21 | _stock = 0.0 |
22 | @@ -76,11 +76,12 @@ |
23 | ' WHERE sm.product_id = {product} \n' \ |
24 | ' AND sm.date < \'{date_to}\' \n' \ |
25 | ' AND sm.state = \'done\' \n' \ |
26 | - ' AND sm.location_id IN {locations} \n' \ |
27 | + ' AND sm.location_id NOT IN {locations} \n' \ |
28 | + ' AND sm.location_dest_id NOT IN {locations} \n' \ |
29 | 'ORDER BY sm.date DESC \n' \ |
30 | - ' LIMIT 1'.format(product = ids[0], |
31 | - date_to = _date_to, |
32 | - locations = tuple(_location_ids)).replace(',)', ')') |
33 | + ' LIMIT 1;'.format(product = ids[0], |
34 | + date_to = _date_to, |
35 | + locations = tuple(_location_ids)).replace(',)', ')') |
36 | cr.execute(_sql_string) |
37 | _last_out_move_tups = cr.fetchall() |
38 | _last_out_move_id = [] |
39 | @@ -98,9 +99,6 @@ |
40 | ' WHERE sm.product_id = {product} \n' \ |
41 | ' AND sm.date < \'{date_to}\' \n' \ |
42 | ' AND sm.state = \'done\' \n' \ |
43 | - ' AND NOT EXISTS (SELECT inv.move_id \n' \ |
44 | - ' FROM stock_inventory_move_rel AS inv \n' \ |
45 | - ' WHERE inv.move_id = sm.id) \n ' \ |
46 | 'ORDER BY sm.date;'.format(product = ids[0], |
47 | date_from = _date_from, |
48 | date_to = _date_to).replace(',)', ')') |
49 | |
50 | === modified file 'purchase_recalculation/wizard/account_product_cost_recalculation.py' |
51 | --- purchase_recalculation/wizard/account_product_cost_recalculation.py 2014-04-22 07:13:07 +0000 |
52 | +++ purchase_recalculation/wizard/account_product_cost_recalculation.py 2014-04-23 11:51:12 +0000 |
53 | @@ -42,26 +42,26 @@ |
54 | } |
55 | |
56 | def _do_recalculation(self, cr, uid, ids, context=None): |
57 | - _recalc_id = self.browse(cr, uid, ids[0], context) |
58 | - _period_id = False |
59 | + _recalc = self.browse(cr, uid, ids[0], context) |
60 | + _period = False |
61 | _dates = {} |
62 | _digits = {} |
63 | |
64 | # najdem ustrezna obdobja |
65 | - if _recalc_id.period_id: |
66 | - _period_id = _recalc_id.period_id |
67 | + if _recalc.period_id: |
68 | + _period = _recalc.period_id |
69 | else: |
70 | raise osv.except_osv(_('Error!'), _('Cannot find suitable dates for recalculation.')) |
71 | |
72 | - _year_start = _period_id.fiscalyear_id.date_start |
73 | - _date_from = _period_id.date_start |
74 | - _date_to = _period_id.date_stop |
75 | + _year_start = _period.fiscalyear_id.date_start |
76 | + _date_from = _period.date_start |
77 | + _date_to = _period.date_stop |
78 | |
79 | # najdem ustrezne izdelke |
80 | _product_ids = [] |
81 | |
82 | - if _recalc_id.product_id: |
83 | - _product_ids.append(_recalc_id.product_id.id) |
84 | + if _recalc.product_id: |
85 | + _product_ids.append(_recalc.product_id.id) |
86 | else: |
87 | _product_ids = self.pool.get('product.product').search(cr, uid, [('active','=',True),('cost_method','=','average'),('type','=','product')]) |
88 | |
89 | @@ -91,16 +91,16 @@ |
90 | # izračunam začetno zalogo in ceno |
91 | _dates['date_from'] = _year_start + ' 00:00:00' |
92 | _dates['date_to'] = _date_from + ' 00:00:00' |
93 | - _start_stock, _start_cost, _start_period = _product._get_stock_and_cost(_dates, _digits) |
94 | + _start_stock, _start_cost, _start_period = _product._get_start_stock_and_cost(_dates, _digits) |
95 | |
96 | # če ni prometa v obdobju pogledam še inventuro |
97 | if not _start_period: |
98 | _dates['date_from'] = _date_from + ' 00:00:00' |
99 | - _start_stock, _start_cost = _product._get_stock_and_cost_inventory(_dates, _digits) |
100 | - elif _start_period.id != _period_id.id: |
101 | - #if _start_period and _start_period.id != _period_id.id: |
102 | - _new_period_id = self.pool.get('account.period').next(cr, uid, _start_period, 1, context) |
103 | - _new_period = self.pool.get('account.period').browse(cr, uid, _new_period_id, context) |
104 | + _start_stock, _start_cost = _product._get_inventory_stock_and_cost(_dates, _digits) |
105 | + elif _start_period.id != _period.id: |
106 | + #if _start_period and _start_period.id != _period.id: |
107 | + _new_period = self.pool.get('account.period').next(cr, uid, _start_period, 1, context) |
108 | + _new_period = self.pool.get('account.period').browse(cr, uid, _new_period, context) |
109 | _dates['date_from'] = _new_period.date_start + ' 00:00:00' |
110 | else: |
111 | _dates['date_from'] = _date_from + ' 00:00:00' |
112 | @@ -118,25 +118,25 @@ |
113 | _end_period_cost = round(_start_cost + _period_cost, _digits['price']) |
114 | |
115 | # izračunam povprečno ceno za obdobje |
116 | - _period_average = False |
117 | + _average_cost = False |
118 | if _end_period_stock and _end_period_stock <> 0: |
119 | - _period_average = abs(round(_end_period_cost / _end_period_stock, _digits['price'])) |
120 | + _average_cost = abs(round(_end_period_cost / _end_period_stock, _digits['price'])) |
121 | elif _period_stock and _period_stock <> 0: |
122 | - _period_average = abs(round(_period_cost / _period_stock, _digits['price'])) |
123 | + _average_cost = abs(round(_period_cost / _period_stock, _digits['price'])) |
124 | |
125 | # zapišem povprečno ceno v tabelo |
126 | - if _period_average and _period_average <> 0: |
127 | + if _average_cost and _average_cost <> 0: |
128 | _dates['date_from'] = _date_from + ' 00:00:00' |
129 | _dates['date_to'] = _date_to + ' 23:59:59' |
130 | |
131 | _product_cost_id = self.pool.get('product.period.cost').search(cr, uid, [('product_id','=', _product.id), |
132 | - ('period_id','=',_period_id.id)]) |
133 | + ('period_id','=',_period.id)]) |
134 | if len(_product_cost_id) <> 0: |
135 | - self.pool.get('product.period.cost').write(cr, uid, _product_cost_id, {'price_unit': _period_average}) |
136 | + self.pool.get('product.period.cost').write(cr, uid, _product_cost_id, {'price_unit': _average_cost}) |
137 | else: |
138 | self.pool.get('product.period.cost').create(cr, uid, {'product_id': _product.id, |
139 | - 'period_id': _period_id.id, |
140 | - 'price_unit': _period_average}) |
141 | + 'period_id': _period.id, |
142 | + 'price_unit': _average_cost}) |
143 | return True |
144 | |
145 | def execute(self, cr, uid, ids, context=None): |
146 | |
147 | === modified file 'purchase_recalculation/wizard/account_product_cost_set.py' |
148 | --- purchase_recalculation/wizard/account_product_cost_set.py 2014-04-22 07:13:07 +0000 |
149 | +++ purchase_recalculation/wizard/account_product_cost_set.py 2014-04-23 11:51:12 +0000 |
150 | @@ -116,11 +116,11 @@ |
151 | ' ELSE 0.0 \n ' \ |
152 | ' END) AS stock_end \n ' \ |
153 | ' FROM stock_move AS sm \n ' \ |
154 | - ' INNER JOIN product_template AS pt ON pt.id = sm.product_id \n ' \ |
155 | + ' INNER JOIN product_product AS pp ON pp.id = sm.product_id \n ' \ |
156 | + ' AND pp.valuation = \'manual_periodic\' \n ' \ |
157 | + ' INNER JOIN product_template AS pt ON pt.id = pp.product_tmpl_id \n ' \ |
158 | ' AND pt.type = \'product\' \n ' \ |
159 | ' AND pt.cost_method = \'average\' \n ' \ |
160 | - ' INNER JOIN product_product AS pp ON pp.id = sm.product_id \n ' \ |
161 | - ' AND pp.valuation = \'manual_periodic\' \n ' \ |
162 | ' WHERE sm.state = \'done\' \n ' \ |
163 | ' AND sm.date <= \'{date_to}\' \n ' \ |
164 | ' AND (sm.location_id IN (SELECT location_id \n ' \ |
165 | @@ -233,8 +233,9 @@ |
166 | ' SUM(sd.stock_start) + SUM(stock_in) - SUM(stock_end) AS cost_quantity, \n ' \ |
167 | ' ROUND((SUM(sd.stock_start) + SUM(stock_in) - SUM(stock_end)) * ppc.price_unit, 2) AS cost_value \n ' \ |
168 | ' FROM stock_data AS sd \n ' \ |
169 | - ' INNER JOIN product_template AS pt ON pt.id = sd.product_id \n ' \ |
170 | - ' INNER JOIN product_period_cost AS ppc ON ppc.product_id = sd.product_id \n ' \ |
171 | + ' INNER JOIN product_product AS pp ON pp.id = sd.product_id \n ' \ |
172 | + ' INNER JOIN product_template AS pt ON pt.id = pp.product_tmpl_id \n ' \ |
173 | + ' INNER JOIN product_period_cost AS ppc ON ppc.product_id = pp.id \n ' \ |
174 | ' AND ppc.period_id = {period_id} \n ' \ |
175 | ' GROUP BY sd.product_id, pt.categ_id, ppc.price_unit \n ' \ |
176 | ' HAVING SUM(sd.stock_start) + SUM(stock_in) - SUM(stock_end) <> 0) \n ' \ |
177 | @@ -387,9 +388,11 @@ |
178 | _location_ids = self.pool.get('stock.location').search(cr, uid, [('usage','=','internal')]) |
179 | _sql_string = ' SELECT sm.product_id AS id \n ' \ |
180 | ' FROM stock_move AS sm \n ' \ |
181 | - ' INNER JOIN product_template AS pt ON pt.id = sm.product_id \n ' \ |
182 | + ' INNER JOIN product_product AS pp ON pp.id = sm.product_id \n ' \ |
183 | + ' AND pp.valuation = \'real_time\' \n ' \ |
184 | + ' INNER JOIN product_template AS pt ON pt.id = pp.product_tmpl_id \n ' \ |
185 | ' AND pt.cost_method = \'average\' \n ' \ |
186 | - ' AND pt.valuation = \'real_time\' \n ' \ |
187 | + ' AND pt.type = \'product\' \n ' \ |
188 | ' WHERE sm.date >= \'{date_from}\' \n' \ |
189 | ' AND sm.date <= \'{date_to}\' \n ' \ |
190 | ' AND sm.state = \'done\' \n ' \ |