diff --git a/addons/stock_landed_costs/stock_landed_costs.py b/addons/stock_landed_costs/stock_landed_costs.py
index 11a99542eab..12fe9e440cc 100644
--- a/addons/stock_landed_costs/stock_landed_costs.py
+++ b/addons/stock_landed_costs/stock_landed_costs.py
@@ -67,7 +67,7 @@ class stock_landed_cost(osv.osv):
for quant in move.quant_ids:
total_cost += quant.cost
total_qty += quant.qty
- vals = dict(product_id = move.product_id.id, move_id = move.id, quantity = move.product_uom_qty, former_cost = total_cost * total_qty, weight = weight, volume = volume)
+ vals = dict(product_id = move.product_id.id, move_id = move.id, quantity = move.product_uom_qty, former_cost = total_cost * total_qty, weight = weight, volume = volume, flag = 'original')
lines.append(vals)
result['valuation_adjustment_lines'] = lines
return {'value': result}
@@ -114,37 +114,70 @@ class stock_landed_cost(osv.osv):
for cost in self.browse(cr, uid, ids, context=None):
total_qty = 0.0
total_cost = 0.0
+ total_weight = 0.0
+ total_volume = 0.0
total_line = 0.0
for line in cost.valuation_adjustment_lines:
- total_qty += line.quantity
- total_cost += line.former_cost
- total_line += 1
+ if line.flag == 'original':
+ total_qty += line.quantity
+ total_cost += line.former_cost
+ total_weight += line.weight
+ total_volume += line.volume
+ total_line += 1
+
+ unlink_ids = line_obj.search(cr, uid, [('cost_id', 'in', ids), ('flag', '=', 'duplicate')], context=context)
+ line_obj.unlink(cr, uid, unlink_ids, context=context)
+ for cost in self.browse(cr, uid, ids, context=None):
+ count = 0.0
+ for line in cost.cost_lines:
+ count += 1
+ for valuation in cost.valuation_adjustment_lines:
+ if count == 1:
+ line_obj.write(cr, uid, valuation.id, {'cost_line_id': line.id}, context=context)
+ continue
+ line_obj.copy(cr, uid, valuation.id, default={'cost_line_id': line.id, 'flag': 'duplicate'}, context=context)
+
for cost in self.browse(cr, uid, ids, context=None):
dict = {}
for line in cost.cost_lines:
for valuation in cost.valuation_adjustment_lines:
- if line.split_method in ('by_quantity', 'by_weight', 'by_volume'):
- per_unit = (line.price_unit / total_qty)
- value = valuation.quantity * per_unit
- if valuation.id not in dict:
- dict.setdefault(valuation.id, value)
- else:
- dict[valuation.id] += value
- elif line.split_method == 'equal':
- per_unit = (line.price_unit / total_line)
- if valuation.id not in dict:
- dict.setdefault(valuation.id, per_unit)
- else:
- dict[valuation.id] += per_unit
- elif line.split_method == 'by_current_cost_price':
- per_unit = (line.price_unit / total_cost)
- value = valuation.former_cost * per_unit
- if valuation.id not in dict:
- dict.setdefault(valuation.id, value)
- else:
- dict[valuation.id] += value
-
+ if valuation.cost_line_id and valuation.cost_line_id.id == line.id:
+ if line.split_method == 'by_quantity':
+ per_unit = (line.price_unit / total_qty)
+ value = valuation.quantity * per_unit
+ if valuation.id not in dict:
+ dict[valuation.id] = value
+ else:
+ dict[valuation.id] += value
+ elif line.split_method == 'by_weight':
+ per_unit = (line.price_unit / total_weight or 1.0)
+ value = valuation.quantity * per_unit
+ if valuation.id not in dict:
+ dict[valuation.id] = value
+ else:
+ dict[valuation.id] += value
+ elif line.split_method == 'by_volume':
+ per_unit = (line.price_unit / total_volume or 1.0)
+ value = valuation.quantity * per_unit
+ if valuation.id not in dict:
+ dict[valuation.id] = value
+ else:
+ dict[valuation.id] += value
+ elif line.split_method == 'equal':
+ per_unit = (line.price_unit / total_line)
+ if valuation.id not in dict:
+ dict[valuation.id] = per_unit
+ else:
+ dict[valuation.id] += per_unit
+ elif line.split_method == 'by_current_cost_price':
+ per_unit = (line.price_unit / total_cost)
+ value = valuation.former_cost * per_unit
+ if valuation.id not in dict:
+ dict[valuation.id] = value
+ else:
+ dict[valuation.id] += value
+
for key, value in dict.items():
line_obj.write(cr, uid, key, {'additional_landed_cost': value}, context=context)
@@ -193,6 +226,7 @@ class stock_valuation_adjustment_lines(osv.osv):
_columns = {
'name': fields.char('Description', size=256),
'cost_id': fields.many2one('stock.landed.cost', 'Landed Cost', required=True, ondelete='cascade'),
+ 'cost_line_id': fields.many2one('stock.landed.cost.lines', 'Cost Line'),
'move_id': fields.many2one('stock.move', 'Stock Move'),
'product_id': fields.many2one('product.product', 'Product', required=True),
'quantity': fields.float('Quantity', digits_compute= dp.get_precision('Product Unit of Measure'), required=True),
@@ -202,10 +236,14 @@ class stock_valuation_adjustment_lines(osv.osv):
'former_cost_per_unit': fields.function(_amount_final, multi='cost', string='Former Cost(Per Unit)', type='float', digits_compute= dp.get_precision('Account'), store=True),
'additional_landed_cost': fields.float('Additional Landed Cost', digits_compute= dp.get_precision('Product Price')),
'final_cost': fields.function(_amount_final, multi='cost', string='Final Cost', type='float', digits_compute= dp.get_precision('Account'), store=True),
+ 'flag': fields.selection([('original', 'Original'), ('duplicate', 'Duplicate')], 'Flag', readonly=True),
}
_defaults = {
'quantity': 1.0,
+ 'weight': 1.0,
+ 'volume': 1.0,
+ 'flag': 'original',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/stock_landed_costs/stock_landed_costs_view.xml b/addons/stock_landed_costs/stock_landed_costs_view.xml
index 2f0feb582f3..816a62d7f1e 100644
--- a/addons/stock_landed_costs/stock_landed_costs_view.xml
+++ b/addons/stock_landed_costs/stock_landed_costs_view.xml
@@ -79,6 +79,7 @@
+