Merge lp:~openerp-dev/openobject-addons/trunk-bug-779145-ron into lp:openobject-addons
- trunk-bug-779145-ron
- Merge into trunk
Proposed by
Rohan Nayani(Open ERP)
Status: | Merged |
---|---|
Merged at revision: | 5226 |
Proposed branch: | lp:~openerp-dev/openobject-addons/trunk-bug-779145-ron |
Merge into: | lp:openobject-addons |
Diff against target: |
282 lines (+63/-25) 6 files modified
sale/sale.py (+1/-0) stock/report/report_stock_move.py (+23/-13) stock/stock.py (+29/-5) stock/wizard/stock_partial_picking.py (+1/-1) stock/wizard/stock_return_picking.py (+7/-5) stock/wizard/stock_return_picking_view.xml (+2/-1) |
To merge this branch: | bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-779145-ron |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rucha (Open ERP) (community) | Approve | ||
Review via email: mp+65324@code.launchpad.net |
Commit message
Description of the change
[FIX]stock,
1)use price_unit field as current cost price,
2)this field used at return picking as historical price unit'
To post a comment you must log in.
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote : | # |
see my comment on the bug.
I just merged the sale part. The rest is much more complex that what have been done here, it should be made as a separate project if we decide to implement that.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'sale/sale.py' |
2 | --- sale/sale.py 2011-08-06 13:24:20 +0000 |
3 | +++ sale/sale.py 2011-08-11 13:22:15 +0000 |
4 | @@ -709,6 +709,7 @@ |
5 | #'state': 'waiting', |
6 | 'note': line.notes, |
7 | 'company_id': order.company_id.id, |
8 | + 'price_unit': line.product_id.standard_price or 0.0 |
9 | }) |
10 | |
11 | if line.product_id: |
12 | |
13 | === modified file 'stock/report/report_stock_move.py' |
14 | --- stock/report/report_stock_move.py 2011-04-05 06:50:13 +0000 |
15 | +++ stock/report/report_stock_move.py 2011-08-11 13:22:15 +0000 |
16 | @@ -94,11 +94,11 @@ |
17 | ELSE 0.0 |
18 | END AS in_qty, |
19 | CASE WHEN sp.type in ('out') THEN |
20 | - sum(sm.product_qty * pu.factor) * pt.standard_price |
21 | + sum(sm.product_qty * pu.factor) * sm.price_unit |
22 | ELSE 0.0 |
23 | END AS out_value, |
24 | CASE WHEN sp.type in ('in') THEN |
25 | - sum(sm.product_qty * pu.factor) * pt.standard_price |
26 | + sum(sm.product_qty * pu.factor) * sm.price_unit |
27 | ELSE 0.0 |
28 | END AS in_value, |
29 | min(sm.id) as sm_id, |
30 | @@ -133,7 +133,7 @@ |
31 | sm.id,sp.type, sm.date,sm.address_id, |
32 | sm.product_id,sm.state,sm.product_uom,sm.date_expected, |
33 | sm.product_id,pt.standard_price, sm.picking_id, sm.product_qty, |
34 | - sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id) |
35 | + sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id, sm.price_unit) |
36 | AS al |
37 | |
38 | GROUP BY |
39 | @@ -176,11 +176,16 @@ |
40 | m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type, |
41 | m.company_id, |
42 | m.state as state, m.prodlot_id as prodlot_id, |
43 | - coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0) as value, |
44 | - CASE when pt.uom_id = m.product_uom THEN |
45 | + case when (pt.cost_method = 'average') then |
46 | + coalesce(sum(-m.price_unit * m.product_qty)::decimal, 0.0) |
47 | + else |
48 | + coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0) |
49 | + end as value, |
50 | + case when pt.uom_id = m.product_uom then |
51 | coalesce(sum(-m.product_qty)::decimal, 0.0) |
52 | - ELSE |
53 | - coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0) END as product_qty |
54 | + else |
55 | + coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0) |
56 | + end as product_qty |
57 | FROM |
58 | stock_move m |
59 | LEFT JOIN stock_picking p ON (m.picking_id=p.id) |
60 | @@ -191,7 +196,7 @@ |
61 | LEFT JOIN stock_location l ON (m.location_id=l.id) |
62 | GROUP BY |
63 | m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id, |
64 | - m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id |
65 | + m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id, pt.cost_method |
66 | ) UNION ALL ( |
67 | SELECT |
68 | -m.id as id, m.date as date, |
69 | @@ -199,11 +204,16 @@ |
70 | m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type, |
71 | m.company_id, |
72 | m.state as state, m.prodlot_id as prodlot_id, |
73 | - coalesce(sum(pt.standard_price * m.product_qty )::decimal, 0.0) as value, |
74 | - CASE when pt.uom_id = m.product_uom THEN |
75 | + case when (pt.cost_method = 'average') then |
76 | + coalesce(sum(m.price_unit * m.product_qty)::decimal, 0.0) |
77 | + else |
78 | + coalesce(sum(pt.standard_price * m.product_qty)::decimal, 0.0) |
79 | + end as value, |
80 | + case when pt.uom_id = m.product_uom then |
81 | coalesce(sum(m.product_qty)::decimal, 0.0) |
82 | - ELSE |
83 | - coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0) END as product_qty |
84 | + else |
85 | + coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0) |
86 | + end as product_qty |
87 | FROM |
88 | stock_move m |
89 | LEFT JOIN stock_picking p ON (m.picking_id=p.id) |
90 | @@ -214,7 +224,7 @@ |
91 | LEFT JOIN stock_location l ON (m.location_dest_id=l.id) |
92 | GROUP BY |
93 | m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id, |
94 | - m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id |
95 | + m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id, pt.cost_method |
96 | ) |
97 | ); |
98 | """) |
99 | |
100 | === modified file 'stock/stock.py' |
101 | --- stock/stock.py 2011-07-11 16:11:22 +0000 |
102 | +++ stock/stock.py 2011-08-11 13:22:15 +0000 |
103 | @@ -1140,6 +1140,19 @@ |
104 | move_obj.unlink(cr, uid, ids2, ctx) |
105 | |
106 | return super(stock_picking, self).unlink(cr, uid, ids, context=context) |
107 | + |
108 | + def get_current_cost_price(self, cr, uid, ids, pick, move, product_price, context=None): |
109 | + """@return: Return Current cost price""" |
110 | + if context is None: |
111 | + context = {} |
112 | + price_unit = 0.0 |
113 | + if (pick.type == 'in') and (move.product_id.cost_method == 'average'): |
114 | + price_unit = product_price |
115 | + elif move.price_unit == 0: |
116 | + price_unit = move.product_id.standard_price |
117 | + else: |
118 | + price_unit = move.price_unit |
119 | + return price_unit |
120 | |
121 | # FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()! |
122 | def do_partial(self, cr, uid, ids, partial_datas, context=None): |
123 | @@ -1217,7 +1230,6 @@ |
124 | {'price_unit': product_price, |
125 | 'price_currency_id': product_currency}) |
126 | |
127 | - |
128 | for move in too_few: |
129 | product_qty = move_product_qty[move.id] |
130 | |
131 | @@ -1229,35 +1241,45 @@ |
132 | 'state':'draft', |
133 | }) |
134 | if product_qty != 0: |
135 | + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) |
136 | defaults = { |
137 | 'product_qty' : product_qty, |
138 | 'product_uos_qty': product_qty, #TODO: put correct uos_qty |
139 | 'picking_id' : new_picking, |
140 | 'state': 'assigned', |
141 | 'move_dest_id': False, |
142 | - 'price_unit': move.price_unit, |
143 | + 'price_unit': price_unit |
144 | } |
145 | prodlot_id = prodlot_ids[move.id] |
146 | if prodlot_id: |
147 | defaults.update(prodlot_id=prodlot_id) |
148 | move_obj.copy(cr, uid, move.id, defaults) |
149 | - |
150 | + if (pick.type == 'in') and (move.product_id.cost_method == 'average'): |
151 | + new_price_unit = move.product_id.standard_price |
152 | + else: |
153 | + new_price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) |
154 | move_obj.write(cr, uid, [move.id], |
155 | { |
156 | 'product_qty' : move.product_qty - product_qty, |
157 | 'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty |
158 | + 'price_unit': new_price_unit or 0.0 |
159 | }) |
160 | |
161 | if new_picking: |
162 | move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking}) |
163 | for move in complete: |
164 | + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) |
165 | + defaults = {'price_unit': price_unit or 0.0} |
166 | if prodlot_ids.get(move.id): |
167 | - move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]}) |
168 | + defaults.update({'prodlot_id': prodlot_ids[move.id]}) |
169 | + move_obj.write(cr, uid, [move.id], defaults) |
170 | for move in too_many: |
171 | + price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context) |
172 | product_qty = move_product_qty[move.id] |
173 | defaults = { |
174 | 'product_qty' : product_qty, |
175 | 'product_uos_qty': product_qty, #TODO: put correct uos_qty |
176 | + 'price_unit': price_unit or 0.0 |
177 | } |
178 | prodlot_id = prodlot_ids.get(move.id) |
179 | if prodlot_ids.get(move.id): |
180 | @@ -1747,6 +1769,7 @@ |
181 | 'product_uom': product.uom_id.id, |
182 | 'product_uos': uos_id, |
183 | 'product_qty': 1.00, |
184 | + 'price_unit': product.standard_price, |
185 | 'product_uos_qty' : self.pool.get('stock.move').onchange_quantity(cr, uid, ids, prod_id, 1.00, product.uom_id.id, uos_id)['value']['product_uos_qty'] |
186 | } |
187 | if not ids: |
188 | @@ -2489,7 +2512,7 @@ |
189 | |
190 | for move in complete: |
191 | if prodlot_ids.get(move.id): |
192 | - self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)}) |
193 | + self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id), 'price_unit': move.product_id.standard_price}) |
194 | self.action_done(cr, uid, [move.id], context=context) |
195 | if move.picking_id.id : |
196 | # TOCHECK : Done picking if all moves are done |
197 | @@ -2574,6 +2597,7 @@ |
198 | 'product_uom': line.product_uom.id, |
199 | 'prodlot_id': lot_id, |
200 | 'date': inv.date, |
201 | + 'price_unit': line.product_id.standard_price |
202 | } |
203 | if change > 0: |
204 | value.update( { |
205 | |
206 | === modified file 'stock/wizard/stock_partial_picking.py' |
207 | --- stock/wizard/stock_partial_picking.py 2011-05-02 18:46:43 +0000 |
208 | +++ stock/wizard/stock_partial_picking.py 2011-08-11 13:22:15 +0000 |
209 | @@ -127,7 +127,7 @@ |
210 | |
211 | if pick_type == 'in': |
212 | move_memory.update({ |
213 | - 'cost' : picking.product_id.standard_price, |
214 | + 'cost' : picking.price_unit, |
215 | 'currency' : picking.product_id.company_id and picking.product_id.company_id.currency_id and picking.product_id.company_id.currency_id.id or False, |
216 | }) |
217 | return move_memory |
218 | |
219 | === modified file 'stock/wizard/stock_return_picking.py' |
220 | --- stock/wizard/stock_return_picking.py 2011-03-18 09:16:07 +0000 |
221 | +++ stock/wizard/stock_return_picking.py 2011-08-11 13:22:15 +0000 |
222 | @@ -21,7 +21,7 @@ |
223 | |
224 | import netsvc |
225 | import time |
226 | - |
227 | +import decimal_precision as dp |
228 | from osv import osv,fields |
229 | from tools.translate import _ |
230 | |
231 | @@ -33,6 +33,7 @@ |
232 | 'quantity' : fields.float("Quantity", required=True), |
233 | 'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"), |
234 | 'move_id' : fields.many2one('stock.move', "Move"), |
235 | + 'price_unit' : fields.float('Cost Price', digits_compute=dp.get_precision('Purchase Price'), help="Historical cost price of product") |
236 | } |
237 | |
238 | stock_return_picking_memory() |
239 | @@ -73,7 +74,7 @@ |
240 | for line in pick.move_lines: |
241 | qty = line.product_qty - return_history[line.id] |
242 | if qty > 0: |
243 | - result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id}) |
244 | + result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id, 'price_unit': line.price_unit}) |
245 | if 'product_return_moves' in fields: |
246 | res.update({'product_return_moves': result1}) |
247 | return res |
248 | @@ -180,9 +181,10 @@ |
249 | 'product_qty': new_qty, |
250 | 'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id, |
251 | new_qty, move.product_uos.id), |
252 | - 'picking_id':new_picking, 'state':'draft', |
253 | - 'location_id':new_location, 'location_dest_id':move.location_id.id, |
254 | - 'date':date_cur,}) |
255 | + 'picking_id': new_picking, 'state': 'draft', |
256 | + 'location_id': new_location, 'location_dest_id': move.location_id.id, |
257 | + 'date': date_cur, |
258 | + 'price_unit': data_get.price_unit}) |
259 | move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]}) |
260 | if not returned_lines: |
261 | raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!")) |
262 | |
263 | === modified file 'stock/wizard/stock_return_picking_view.xml' |
264 | --- stock/wizard/stock_return_picking_view.xml 2011-03-04 13:47:28 +0000 |
265 | +++ stock/wizard/stock_return_picking_view.xml 2011-08-11 13:22:15 +0000 |
266 | @@ -18,7 +18,7 @@ |
267 | <tree editable="bottom" string="Product Moves"> |
268 | <field name="product_id" /> |
269 | <field name="quantity" /> |
270 | - |
271 | + <field name="price_unit" /> |
272 | </tree> |
273 | </field> |
274 | </record> |
275 | @@ -31,6 +31,7 @@ |
276 | <form> |
277 | <field name="product_id" /> |
278 | <field name="quantity" /> |
279 | + <field name="price_unit" /> |
280 | </form> |
281 | </field> |
282 | </record> |
thanks for the great fix,
while testing the fix I have found somewhere its taking wrong values and improved it,
otherwise it seems working fine for most of the cases