diff --git a/addons/product/product.py b/addons/product/product.py index 52e53912540..a7ed3b2dd14 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -303,12 +303,12 @@ class product_template(osv.osv): 'standard_price': fields.property('', type = 'float', view_load=True, help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user", string="Cost"), - #fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user"), 'volume': fields.float('Volume', help="The volume in m3."), 'weight': fields.float('Gross Weight', digits_compute=dp.get_precision('Stock Weight'), help="The gross weight in Kg."), 'weight_net': fields.float('Net Weight', digits_compute=dp.get_precision('Stock Weight'), help="The net weight in Kg."), - 'cost_method': fields.selection([('standard','Standard Price'), ('average','Average Price')], 'Costing Method', required=True, - help="Standard Price: The cost price is manually updated at the end of a specific period (usually every year). \nAverage Price: The cost price is recomputed at each incoming shipment."), + 'cost_method': fields.property('', type='selection', view_load=True, selection = [('standard','Standard Price'), ('average','Average Price')], + help="Standard Price: The cost price is manually updated at the end of a specific period (usually every year). \nAverage Price: The cost price is recomputed at each incoming shipment.", + string="Costing Method"), 'warranty': fields.float('Warranty'), 'sale_ok': fields.boolean('Can be Sold', help="Specify if the product can be selected in a sales order line."), 'state': fields.selection([('',''), diff --git a/addons/stock/product.py b/addons/stock/product.py index 29445f671ee..c0f7026dfcf 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -202,7 +202,6 @@ class product_product(osv.osv): """ 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') @@ -277,12 +276,18 @@ class product_product(osv.osv): if date_values: where.append(tuple(date_values)) + #It depends on the company of the user + user = self.pool.get("res.users").browse(cr, uid, uid, context=context) + where.append(user.company_id.id) + prodlot_id = context.get('prodlot_id', False) prodlot_clause = '' if prodlot_id: prodlot_clause = ' and prodlot_id = %s ' where += [prodlot_id] + + # TODO: perhaps merge in one query. if 'in' in what: # all moves from a location out of the set to a location in the set @@ -293,6 +298,7 @@ class product_product(osv.osv): 'and location_dest_id IN %s '\ 'and product_id IN %s '\ 'and state IN %s ' + (date_str and 'and '+date_str+' ' or '') +' '\ + 'and company_id = %s '\ + prodlot_clause + 'group by product_id,product_uom',tuple(where)) results = cr.fetchall() @@ -305,6 +311,7 @@ class product_product(osv.osv): 'and location_dest_id NOT IN %s '\ 'and product_id IN %s '\ 'and state in %s ' + (date_str and 'and '+date_str+' ' or '') + ' '\ + 'and company_id = %s '\ + prodlot_clause + 'group by product_id,product_uom',tuple(where)) results2 = cr.fetchall() diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 764d9de453e..8c93c5a5ae0 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1277,6 +1277,38 @@ class stock_picking(osv.osv): {'price_unit': product_price, 'price_currency_id': product_currency}) + #Average price computation when returning products + if (pick.type == 'out') and (move.product_id.cost_method == 'average'): + orig_move_id = move_obj.search(cr, uid, [('move_history_ids2', 'in', [move.id])], context=context) + if len(orig_move_id) == 1: + #Is it ok to repeat code here? + move_orig = move_obj.browse(cr, uid, orig_move_id[0], context=context) + product = product_obj.browse(cr, uid, move.product_id.id) + move_currency_id = move.company_id.currency_id.id + context['currency_id'] = move_currency_id + qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id) + + if product.id in product_avail: + product_avail[product.id] += qty + else: + product_avail[product.id] = product.qty_available + if qty > 0: + new_price = currency_obj.compute(cr, uid, product_currency, + move_currency_id, move_orig.price_unit) + new_price = uom_obj._compute_price(cr, uid, product_uom, new_price, + product.uom_id.id) + # Get the standard price + amount_unit = product.price_get('standard_price', context=context)[product.id] + new_std_price = ((amount_unit * product_avail[product.id])\ + - (new_price * qty))/(product_avail[product.id] - qty) + # Write the field according to price type field + product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price}) + + # Record the values that were chosen in the wizard, so they can be + # used for inventory valuation if real-time valuation is enabled. + move_obj.write(cr, uid, [move.id], + {'price_unit': move_orig.price_unit, + 'price_currency_id': product_currency}) for move in too_few: product_qty = move_product_qty[move.id]