[IMP] Clean average yml and add company_id for stock move of inventory

bzr revid: jco@openerp.com-20130514132322-93wlx9dsr2d0evx5
This commit is contained in:
Josse Colpaert 2013-05-14 15:23:22 +02:00
parent b5055f67a4
commit 55d4dd6a7a
4 changed files with 32 additions and 34 deletions

View File

@ -4,8 +4,7 @@
<record id="product_product_jambon" model="product.product">
<field name="supply_method">buy</field>
<field name="list_price">7.0</field>
<!--<field name="standard_price">5.0</field>
<field name="cost_method">standard</field>-->
<field name="standard_price">5.0</field>
<field name="uom_id" ref="product.product_uom_unit"/>
<field name="uom_po_id" ref="product.product_uom_unit"/>
<field name="uos_id" ref="product.product_uom_kgm" />

View File

@ -1,13 +1,11 @@
-
Set a product as using average price. TODO do we need to fill its standard_price?
Set a product as using average price.
-
!record {model: product.product, id: product_average_icecream}:
default_code: AVG
name: Average Ice Cream
type: product
categ_id: product.product_category_1
list_price: 100.0
standard_price: 70.0
uom_id: product.product_uom_kgm
uom_po_id: product.product_uom_kgm
procure_method: make_to_stock
@ -17,7 +15,7 @@
property_stock_account_output: account.o_income
description: Average Ice Cream can be mass-produced and thus is widely available in developed parts of the world. Ice cream can be purchased in large cartons (vats and squrounds) from supermarkets and grocery stores, in smaller quantities from ice cream shops, convenience stores, and milk bars, and in individual servings from small carts or vans at public events.
-
I create a draft Purchase Order for first in move for 10 pieces at 60€
I create a draft Purchase Order for first incoming shipment for 10 pieces at 60€
-
!record {model: purchase.order, id: purchase_order_average1}:
partner_id: base.res_partner_3
@ -30,7 +28,7 @@
price_unit: 60.0
name: 'Average Ice Cream'
-
I create a draft Purchase Order for second shipment for 30 pieces at 80€
I create a draft Purchase Order for second incoming shipment for 30 pieces at 80€
-
!record {model: purchase.order, id: purchase_order_average2}:
partner_id: base.res_partner_3
@ -60,16 +58,15 @@
-
!python {model: stock.partial.picking}: |
pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_average1")).picking_ids
print pick_ids
partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
self.do_partial(cr, uid, [partial_id])
-
Check the standard price of the product (average icecream). TOD0 you could check the qty_available with an assert. TODO the error message if the assert fails is wrong
Check the standard price of the product (average icecream).
-
!python {model: product.product}: |
print self.browse(cr, uid, ref("product_average_icecream")).qty_available
assert self.browse(cr, uid, ref("product_average_icecream")).standard_price == 60.0, 'Standard price should not change while receiving products!'
product = self.browse(cr, uid, ref("product_average_icecream")
assert product.qty_available == 10.0, 'Wrong quantity in stock after first reception'
assert product.standard_price == 60.0, 'Standard price should be the price of the first reception!'
-
Process the reception of purchase order 2
-
@ -81,14 +78,15 @@
Check the standard price TODO the error message if the assert fails is wrong
-
!python {model: product.product}: |
assert self.browse(cr, uid, ref("product_average_icecream")).standard_price == 75.0, 'Standard price should not change while receiving products!'
assert self.browse(cr, uid, ref("product_average_icecream")).standard_price == 75.0,
'After second reception, the standard price should be the weighted average of the 2 receptions'
-
Let us send some goods
Create picking to send some goods
-
!record {model: stock.picking, id: outgoing_average_shipment}:
type: out
-
Picking needs movement from stock
Create move for picking
-
!record {model: stock.move, id: outgoing_shipment_average_icecream}:
picking_id: outgoing_average_shipment
@ -110,8 +108,8 @@
Check the standard price (60 * 10 + 30 * 80) / 40 = 75.0 did not change
-
!python {model: product.product}: |
assert self.browse(cr, uid, ref("product_average_icecream")).standard_price == 75.0, 'Standard price as average price of second reception incorrect!'
assert self.browse(cr, uid, ref("product_average_icecream")).qty_available == 20.0, 'Pieces were not picked correctly'
assert self.browse(cr, uid, ref("product_average_icecream")).standard_price == 75.0, 'Standard price should not have changed with outgoing picking!'
assert self.browse(cr, uid, ref("product_average_icecream")).qty_available == 20.0, 'Pieces were not picked correctly as the quantity on hand is wrong'
-
Make a new purchase order with 500 g Average Ice Cream at a price of 100 TODO the unit_price is 1 here
-
@ -137,9 +135,9 @@
partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
self.do_partial(cr, uid, [partial_id])
-
Check price is (75.0*20 + 500) / 20.5 = 97.56097561 TODO assert the qty available, remove print statements, write some more explicit assertion error messages
Check price is (75.0*20 + 500) / 20.5 = 97.56097561
-
!python {model: product.product}: |
print self.browse(cr, uid, ref("product_average_icecream")).qty_available
print self.browse(cr, uid, ref("product_average_icecream")).standard_price
product = self.browse(cr, uid, ref("product_average_icecream"))
assert product.qty_available == 20.5, 'Reception of purchase order in grams leads to wrong quantity in stock'
assert round(self.browse(cr, uid, ref("product_average_icecream")).standard_price, 2) == 97.56, 'Standard price as average price of third reception with other UoM incorrect!'

View File

@ -197,7 +197,11 @@ class product_product(osv.osv):
return res
def _get_locations_from_context(self, cr, uid, ids, context=None):
#TODO add some docstring
'''
Parses the context and returns a list of location_ids based on it.
It will return all stock locations when no parameters are given
Possible parameters are shop, warehouse, location, force_company, compute_child
'''
if context is None:
context = {}
location_obj = self.pool.get('stock.location')
@ -234,25 +238,22 @@ class product_product(osv.osv):
# build the list of ids of children of the location given by id
if context.get('compute_child',True):
print location_ids
print context.get("force_company", False)
if context.get('force_company', False):
child_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', location_ids), ('company_id', '=', context['force_company'])])
else:
child_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', location_ids)])
location_ids = child_location_ids or location_ids
print location_ids
return location_ids
def _get_date_query(self, cr, uid, ids, context):
#TODO add some docstring
'''
Parses the context and returns the dates query string needed to be processed in _get_product_available
It searches for a from_date and to_date
'''
from_date = context.get('from_date',False)
to_date = context.get('to_date',False)
date_str = False
date_values = False
whereadd = []
if from_date and to_date:
@ -271,15 +272,14 @@ class product_product(osv.osv):
def get_product_available(self, cr, uid, ids, context=None):
""" Finds whether product is available or not in particular warehouse.
@return: Dictionary of values
""" Finds the quantity available of product(s) depending on parameters in the context
for date, location, state (allows e.g. for calculating future stock), what,
production lot
@return: Dictionary of values for every product id
"""
#TODO complete the docstring with possible keys in context + their effect
if context is None:
context = {}
location_obj = self.pool.get('stock.location')
warehouse_obj = self.pool.get('stock.warehouse')
shop_obj = self.pool.get('sale.shop')
states = context.get('states',[])
what = context.get('what',())

View File

@ -1628,7 +1628,7 @@ class stock_move(osv.osv):
if (record.state=='done') and (record.location_dest_id.usage == 'view' ):
raise osv.except_osv(_('Error'), _('You cannot move product %s to a location of type view %s.')% (record.product_id.name, record.location_dest_id.name))
return True
#TODO: change demo data for this to be possible
def _check_company_location(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids, context=context):
if record.location_id.company_id and (record.company_id.id != record.location_id.company_id.id):
@ -2990,6 +2990,7 @@ class stock_inventory(osv.osv):
'product_uom': line.product_uom.id,
'prodlot_id': lot_id,
'date': inv.date,
'company_id': line.location_id.company_id.id
}
if change > 0: