[IMP] Update of outgoing accounting entries with right price
bzr revid: jco@openerp.com-20130426163606-dhpp042mhd858uyr
This commit is contained in:
+23
-14
@@ -2222,23 +2222,17 @@ class stock_move(osv.osv):
|
||||
(move.product_id.categ_id.name, move.product_id.categ_id.id,))
|
||||
return journal_id, acc_src, acc_dest, acc_valuation
|
||||
|
||||
def _get_reference_accounting_values_for_valuation(self, cr, uid, move, context=None):
|
||||
"""
|
||||
Return the reference amount and reference currency representing the inventory valuation for this move.
|
||||
These reference values should possibly be converted before being posted in Journals to adapt to the primary
|
||||
and secondary currencies of the relevant accounts.
|
||||
"""
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
|
||||
#We can use a preliminary type
|
||||
def get_reference_amount(self, cr, uid, move, qty, context=None):
|
||||
# if product is set to average price and a specific value was entered in the picking wizard,
|
||||
# we use it
|
||||
|
||||
# by default the reference currency is that of the move's company
|
||||
reference_currency_id = move.company_id.currency_id.id
|
||||
|
||||
default_uom = move.product_id.uom_id.id
|
||||
qty = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
|
||||
|
||||
# if product is set to average price and a specific value was entered in the picking wizard,
|
||||
# we use it
|
||||
if move.product_id.cost_method == 'average' and move.price_unit:
|
||||
|
||||
#I use
|
||||
if move.product_id.cost_method != 'standard' and move.price_unit:
|
||||
reference_amount = qty * move.price_unit
|
||||
reference_currency_id = move.price_currency_id.id or reference_currency_id
|
||||
|
||||
@@ -2250,7 +2244,22 @@ class stock_move(osv.osv):
|
||||
currency_ctx = dict(context, currency_id = move.company_id.currency_id.id)
|
||||
amount_unit = move.product_id.price_get('standard_price', context=currency_ctx)[move.product_id.id]
|
||||
reference_amount = amount_unit * qty
|
||||
|
||||
return reference_amount, reference_currency_id
|
||||
|
||||
|
||||
def _get_reference_accounting_values_for_valuation(self, cr, uid, move, context=None):
|
||||
"""
|
||||
Return the reference amount and reference currency representing the inventory valuation for this move.
|
||||
These reference values should possibly be converted before being posted in Journals to adapt to the primary
|
||||
and secondary currencies of the relevant accounts.
|
||||
"""
|
||||
product_uom_obj = self.pool.get('product.uom')
|
||||
|
||||
default_uom = move.product_id.uom_id.id
|
||||
qty = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
|
||||
|
||||
reference_amount, reference_currency_id = self.get_reference_amount(cr, uid, move, qty, context=context)
|
||||
return reference_amount, reference_currency_id
|
||||
|
||||
|
||||
|
||||
@@ -115,16 +115,21 @@ class stock_move(osv.osv):
|
||||
if move.picking_id.type == 'out' and cost_method in ['fifo', 'lifo']:
|
||||
if not move.move_returned_from:
|
||||
tuples = product_obj.get_stock_matchings_fifolifo(cr, uid, [product.id], product_qty, cost_method == 'fifo', context=context)
|
||||
price_amount = 0.0
|
||||
amount = 0.0
|
||||
for match in tuples:
|
||||
matchvals = {'move_in_id': match[0], 'qty': match[1], 'price_unit': match[2],
|
||||
matchvals = {'move_in_id': match[0], 'qty': match[1],
|
||||
'move_out_id': move.id}
|
||||
match_id = matching_obj.create(cr, uid, matchvals, context=context)
|
||||
move_in = self.browse(cr, uid, match[0], context=context)
|
||||
self.write(cr, uid, match[0], { 'qty_remaining': move_in.qty_remaining - match[1]}, context=context)
|
||||
price_amount += match[1] * match[2]
|
||||
amount += match[1]
|
||||
self.write(cr, uid, move.id, {'price_unit': price_amount / amount}, context=context)
|
||||
#Should also write this price to the standard price of the product
|
||||
else:
|
||||
#We should find something to do when a stock matching is linked to the returned move already
|
||||
if move.move_returned_from.matching_ids_in:
|
||||
pass
|
||||
#We should put the price unit of the returned move, when it is something that gets returned
|
||||
self.write(cr, uid, move.id, {'price_unit': move.move_returned_from.price_unit}, context=context)
|
||||
return True
|
||||
|
||||
class stock_move_matching(osv.osv):
|
||||
|
||||
Reference in New Issue
Block a user