Merge lp:~openerp-dev/openobject-addons/ron-dev-addons2 into lp:~openerp-dev/openobject-addons/trunk-dev-addons2

Proposed by Rohan Nayani(Open ERP)
Status: Merged
Merged at revision: 3954
Proposed branch: lp:~openerp-dev/openobject-addons/ron-dev-addons2
Merge into: lp:~openerp-dev/openobject-addons/trunk-dev-addons2
Diff against target: 372 lines (+192/-100)
4 files modified
purchase/__openerp__.py (+1/-1)
purchase/test/purchase_on_average_price.yml (+107/-0)
report_intrastat/report_intrastat_data.xml (+3/-0)
stock/wizard/stock_partial_picking.py (+81/-99)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/ron-dev-addons2
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+45820@code.launchpad.net

Description of the change

https://launchpad.net/bugs/697209
https://launchpad.net/bugs/697085
purchase:Add Yml file which has product price Costing Method is Average Price

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase/__openerp__.py'
2--- purchase/__openerp__.py 2010-10-26 06:08:44 +0000
3+++ purchase/__openerp__.py 2011-01-11 09:02:02 +0000
4@@ -54,7 +54,7 @@
5 'report/purchase_report_view.xml',
6 'board_purchase_view.xml',
7 ],
8- 'test': [
9+ 'test': ['test/purchase_on_average_price.yml',
10 'test/purchase_from_order.yml',
11 'test/purchase_from_manual.yml',
12 'test/purchase_from_picking.yml',
13
14=== added file 'purchase/test/purchase_on_average_price.yml'
15--- purchase/test/purchase_on_average_price.yml 1970-01-01 00:00:00 +0000
16+++ purchase/test/purchase_on_average_price.yml 2011-01-11 09:02:02 +0000
17@@ -0,0 +1,107 @@
18+-
19+ In order to test Checking of Cost price of product if the product price "Costing Method"
20+ is "Average Price" and we change value of product on incoming shipment
21+
22+-
23+ I create product.
24+-
25+ !record {model: product.product, id: product_product_pen0 }:
26+ categ_id: product.product_category_3
27+ cost_method: average
28+ name: Pen drive
29+ procure_method: make_to_stock
30+ supply_method: buy
31+ type: product
32+ standard_price: 1500.0
33+ list_price: 1500.0
34+ supply_method: buy
35+ uom_id: product.product_uom_unit
36+ uom_po_id: product.product_uom_unit
37+ volume: 0.0
38+ warranty: 0.0
39+ weight: 0.0
40+
41+-
42+ Update Starting Real Stock And Virtual Stock threw Wizard
43+-
44+ !record {model: stock.change.product.qty , id: stock_change_product_id }:
45+ product_id: product_product_pen0
46+ new_quantity: 2.0
47+ location_id: stock.stock_location_stock
48+-
49+ Then, Click on "Update Price" button of this wizard.
50+-
51+ !python {model: stock.change.product.qty }: |
52+ self.change_product_qty(cr, uid, [ref('stock_change_product_id')], {'active_id': ref('product_product_pen0')})
53+-
54+ I create purchase order for Pen drive.
55+-
56+ !record {model: purchase.order, id: purchase_order_po11}:
57+ company_id: base.main_company
58+ date_order: '2010-05-11'
59+ invoice_method: order
60+ location_id: stock.stock_location_stock
61+ order_line:
62+ - date_planned: '2010-05-13'
63+ name: Pen drive
64+ price_unit: 1500.0
65+ product_id: 'product_product_pen0'
66+ product_qty: 2.0
67+ product_uom: product.product_uom_unit
68+ state: draft
69+ partner_address_id: base.res_partner_address_7
70+ partner_id: base.res_partner_4
71+ pricelist_id: purchase.list0
72+-
73+ PO Initially in Draft State .
74+-
75+ !assert {model: purchase.order, id: purchase_order_po11}:
76+ - state == 'draft'
77+-
78+ PO Going to Draft To Confirm State
79+-
80+ !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_po11}
81+-
82+ I check that the Order has transit from draft state to confirm state.
83+-
84+ !assert {model: purchase.order, id: purchase_order_po11}:
85+ - state == 'approved'
86+-
87+ I receive the order of the supplier the Incoming Shipments menu.
88+-
89+ !python {model: stock.picking }: |
90+ import time
91+ procurement_obj = self.pool.get('procurement.order')
92+ proc_ids = procurement_obj.browse(cr, uid, [ref('purchase_order_po11')])[0]
93+ picking_ids = self.search(cr, uid, [('purchase_id', '=', proc_ids.id),('type','=','in')])
94+ pickings = self.browse(cr, uid, picking_ids)
95+ for picking in pickings:
96+ move = picking.move_lines[0]
97+ partial_datas = {
98+ 'partner_id': picking.address_id.partner_id.id,
99+ 'address_id': picking.address_id.id,
100+ 'delivery_date' : time.strftime('%Y-%m-%d')
101+ }
102+ partial_datas['move%s'%(move.id)]= {
103+ 'product_id': move.product_id,
104+ 'product_qty': move.product_qty,
105+ 'product_uom': move.product_uom.id,
106+ 'product_price' : 1000.0,
107+ }
108+ self.do_partial(cr, uid, [picking.id], partial_datas)
109+-
110+ I confirm the Reservation.
111+-
112+ !python {model: stock.move }: |
113+ procurement_obj = self.pool.get('procurement.order')
114+ picking_obj = self.pool.get('stock.picking')
115+ proc_ids = procurement_obj.browse(cr, uid, [ref('purchase_order_po11')])[0]
116+ picking_ids = picking_obj.search(cr, uid, [('purchase_id', '=', proc_ids.id),('type','=','in')])
117+ move_ids = self.search(cr, uid, [('picking_id', '=', picking_ids)])
118+ self.action_done(cr,uid,move_ids)
119+-
120+ Compare With Avarage Price Has Been Updated that is Correct
121+-
122+ !assert {model: product.product, id: product_product_pen0 ,string: Updated Avarage Price Has not been Correct}:
123+ - standard_price == 1250
124+
125
126=== modified file 'report_intrastat/report_intrastat_data.xml'
127--- report_intrastat/report_intrastat_data.xml 2008-09-10 17:56:00 +0000
128+++ report_intrastat/report_intrastat_data.xml 2011-01-11 09:02:02 +0000
129@@ -4,6 +4,9 @@
130 <record id="base.de" model="res.country">
131 <field eval="True" name="intrastat"/>
132 </record>
133+ <record id="base.be" model="res.country">
134+ <field eval="True" name="intrastat"/>
135+ </record>
136 <record id="base.at" model="res.country">
137 <field eval="True" name="intrastat"/>
138 </record>
139
140=== modified file 'stock/wizard/stock_partial_picking.py'
141--- stock/wizard/stock_partial_picking.py 2011-01-10 15:43:57 +0000
142+++ stock/wizard/stock_partial_picking.py 2011-01-11 09:02:02 +0000
143@@ -28,54 +28,71 @@
144 _name = "stock.partial.picking"
145 _description = "Partial Picking"
146 _columns = {
147- 'date': fields.datetime('Date', required=True),
148- 'product_moves_out' : fields.one2many('stock.move.memory.out', 'wizard_id', 'Moves'),
149- 'product_moves_in' : fields.one2many('stock.move.memory.in', 'wizard_id', 'Moves'),
150+ 'date': fields.datetime('Date', required=True),
151+ 'product_moves_out' : fields.one2many('stock.move.memory.out', 'wizard_id', 'Moves'),
152+ 'product_moves_in' : fields.one2many('stock.move.memory.in', 'wizard_id', 'Moves'),
153 }
154-
155- def __is_in(self,cr, uid, pick_ids):
156- """
157- @return: True if one of the moves has as picking type 'in'
158- """
159- if not pick_ids:
160- return False
161-
162+
163+ def get_picking_type(self, cr, uid, picking, context=None):
164+ picking_type = picking.type
165+ for move in picking.move_lines:
166+ if picking.type == 'in' and move.product_id.cost_method == 'average':
167+ picking_type = 'in'
168+ return picking_type
169+
170+ def default_get(self, cr, uid, fields, context=None):
171+ """ To get default values for the object.
172+ @param self: The object pointer.
173+ @param cr: A database cursor
174+ @param uid: ID of the user currently logged in
175+ @param fields: List of fields for which we want default values
176+ @param context: A standard dictionary
177+ @return: A dictionary which of fields with values.
178+ """
179+ if context is None:
180+ context = {}
181+
182 pick_obj = self.pool.get('stock.picking')
183- pick_ids = pick_obj.search(cr, uid, [('id','in',pick_ids)])
184-
185-
186- for pick in pick_obj.browse(cr, uid, pick_ids):
187- for move in pick.move_lines:
188- if pick.type == 'in' and move.product_id.cost_method == 'average':
189- return True
190- return False
191-
192- def __get_picking_type(self, cr, uid, pick_ids):
193- if self.__is_in(cr, uid, pick_ids):
194- return "product_moves_in"
195- else:
196- return "product_moves_out"
197-
198- def view_init(self, cr, uid, fields_list, context=None):
199- res = super(stock_partial_picking, self).view_init(cr, uid, fields_list, context=context)
200+ res = super(stock_partial_picking, self).default_get(cr, uid, fields, context=context)
201+ picking_ids = context.get('active_ids', [])
202+ if not picking_ids:
203+ return res
204+
205+ result = []
206+ for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
207+ pick_type = self.get_picking_type(cr, uid, pick, context=context)
208+ for m in pick.move_lines:
209+ if m.state in ('done', 'cancel'):
210+ continue
211+ result.append(self.__create_partial_picking_memory(m, pick_type))
212+
213+ if 'product_moves_in' in fields:
214+ res.update({'product_moves_in': result})
215+ if 'product_moves_out' in fields:
216+ res.update({'product_moves_out': result})
217+ if 'date' in fields:
218+ res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
219 return res
220-
221- def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
222- result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
223-
224-
225+
226+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
227+ result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
228+
229+ pick_obj = self.pool.get('stock.picking')
230 picking_ids = context.get('active_ids', False)
231- picking_type = self.__get_picking_type(cr, uid, picking_ids)
232
233+ for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
234+ picking_type = self.get_picking_type(cr, uid, pick, context=context)
235+
236 _moves_arch_lst = """<form string="%s">
237 <field name="date" invisible="1"/>
238 <separator colspan="4" string="%s"/>
239 <field name="%s" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" ></field>
240- """ % (_('Process Document'), _('Products'), picking_type)
241+ """ % (_('Process Document'), _('Products'), "product_moves_" + picking_type)
242 _moves_fields = result['fields']
243+
244+ # add field related to picking type only
245 _moves_fields.update({
246- 'product_moves_in' : {'relation': 'stock.move.memory.in', 'type' : 'one2many', 'string' : 'Product Moves'},
247- 'product_moves_out' : {'relation': 'stock.move.memory.out', 'type' : 'one2many', 'string' : 'Product Moves'}
248+ 'product_moves_' + picking_type: {'relation': 'stock.move.memory.'+picking_type, 'type' : 'one2many', 'string' : 'Product Moves'},
249 })
250
251 _moves_arch_lst += """
252@@ -92,44 +109,22 @@
253 result['fields'] = _moves_fields
254 return result
255
256- def __create_partial_picking_memory(self, picking, is_in):
257+ def __create_partial_picking_memory(self, picking, pick_type):
258 move_memory = {
259- 'product_id' : picking.product_id.id,
260- 'quantity' : picking.product_qty,
261- 'product_uom' : picking.product_uom.id,
262- 'prodlot_id' : picking.prodlot_id.id,
263- 'move_id' : picking.id,
264+ 'product_id' : picking.product_id.id,
265+ 'quantity' : picking.product_qty,
266+ 'product_uom' : picking.product_uom.id,
267+ 'prodlot_id' : picking.prodlot_id.id,
268+ 'move_id' : picking.id,
269 }
270-
271- if is_in:
272+
273+ if pick_type == 'in':
274 move_memory.update({
275- 'cost' : picking.product_id.standard_price,
276- '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,
277+ 'cost' : picking.product_id.standard_price,
278+ 'currency' : picking.product_id.company_id.currency_id.id,
279 })
280 return move_memory
281
282- def __get_active_stock_pickings(self, cr, uid, context=None):
283- pick_obj = self.pool.get('stock.picking')
284- if not context:
285- context = {}
286-
287- res = []
288- for pick in pick_obj.browse(cr, uid, context.get('active_ids', []), context):
289- need_product_cost = (pick.type == 'in')
290- for m in pick.move_lines:
291- if m.state in ('done', 'cancel'):
292- continue
293- res.append(self.__create_partial_picking_memory(m, need_product_cost))
294-
295- return res
296-
297- _defaults = {
298- 'product_moves_in' : __get_active_stock_pickings,
299- 'product_moves_out' : __get_active_stock_pickings,
300- 'date' : lambda *a : time.strftime('%Y-%m-%d %H:%M:%S'),
301- }
302-
303-
304 def do_partial(self, cr, uid, ids, context=None):
305 """ Makes partial moves and pickings done.
306 @param self: The object pointer.
307@@ -140,6 +135,9 @@
308 @return: A dictionary which of fields with values.
309 """
310 pick_obj = self.pool.get('stock.picking')
311+ move_obj = self.pool.get('stock.move')
312+ location_obj = self.pool.get('stock.location')
313+
314 picking_ids = context.get('active_ids', False)
315 partial = self.browse(cr, uid, ids[0], context=context)
316 partial_datas = {
317@@ -147,40 +145,24 @@
318 }
319
320 for pick in pick_obj.browse(cr, uid, picking_ids, context=context):
321- need_product_cost = (pick.type == 'in')
322- moves_list = need_product_cost and partial.product_moves_in or partial.product_moves_out
323- p_moves = {}
324- for product_move in moves_list:
325- p_moves[product_move.move_id.id] = product_move
326-
327-
328- for move in pick.move_lines:
329- if move.state in ('done', 'cancel'):
330- continue
331- if not p_moves.get(move.id):
332- continue
333-
334- partial_datas['move%s' % (move.id)] = {
335- 'product_id' : p_moves[move.id].id,
336- 'product_qty' : p_moves[move.id].quantity,
337- 'product_uom' :p_moves[move.id].product_uom.id,
338- 'prodlot_id' : p_moves[move.id].prodlot_id.id,
339+ picking_type = self.get_picking_type(cr, uid, pick, context=context)
340+ moves_list = picking_type == 'in' and partial.product_moves_in or partial.product_moves_out
341+
342+ for move in moves_list:
343+ partial_datas['move%s' % (move.move_id.id)] = {
344+ 'product_id': move.id,
345+ 'product_qty': move.quantity,
346+ 'product_uom': move.product_uom.id,
347+ 'prodlot_id': move.prodlot_id.id,
348 }
349-
350-
351- if (move.picking_id.type == 'in') and (move.product_id.cost_method == 'average'):
352+ if (picking_type == 'in') and (move.product_id.cost_method == 'average'):
353 partial_datas['move%s' % (move.id)].update({
354- 'product_price' : p_moves[move.id].cost,
355- 'product_currency': p_moves[move.id].currency.id,
356+ 'product_price' : move.cost,
357+ 'product_currency': move.currency.id,
358 })
359 pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
360- return {'type': 'ir.actions.act_window_close'}
361-
362-
363-
364+ return {}
365
366 stock_partial_picking()
367
368-
369-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
370-
371+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
372\ No newline at end of file

Subscribers

People subscribed via source and target branches