From f3168065b638490802cfef78362e568587aa69f6 Mon Sep 17 00:00:00 2001
From: "ron@tinyerp.com" <>
Date: Tue, 21 Jun 2011 14:56:42 +0530
Subject: [PATCH 1/9] [FIX]stock,sale,purchase:Fixed=> 1)use price_unit field
as currenct cost price 2)this field used at return picking as historical
price unit
lp bug: https://launchpad.net/bugs/779145 fixed
bzr revid: ron@tinyerp.com-20110621092642-3druty1bqzkjczv0
---
addons/sale/sale.py | 1 +
addons/stock/stock.py | 32 ++++++++++++++++---
addons/stock/wizard/stock_return_picking.py | 10 +++---
.../wizard/stock_return_picking_view.xml | 3 +-
4 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 0b436f0dc91..09f047929c4 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -709,6 +709,7 @@ class sale_order(osv.osv):
#'state': 'waiting',
'note': line.notes,
'company_id': order.company_id.id,
+ 'price_unit': line.product_id.standard_price or 0.0
})
if line.product_id:
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index d478ab39c9c..f6e4d1f08ff 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1140,6 +1140,19 @@ class stock_picking(osv.osv):
move_obj.unlink(cr, uid, ids2, ctx)
return super(stock_picking, self).unlink(cr, uid, ids, context=context)
+
+ def get_current_cost_price(self, cr, uid, ids, pick, move, product_price, context=None):
+ """@return: Return Current cost price"""
+ if context is None:
+ context = {}
+ price_unit = 0.0
+ if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
+ price_unit = product_price
+ elif move.price_unit == 0:
+ price_unit = move.product_id.standard_price
+ else:
+ price_unit = move.price_unit
+ return price_unit
# FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()!
def do_partial(self, cr, uid, ids, partial_datas, context=None):
@@ -1217,7 +1230,6 @@ class stock_picking(osv.osv):
{'price_unit': product_price,
'price_currency_id': product_currency})
-
for move in too_few:
product_qty = move_product_qty[move.id]
@@ -1229,35 +1241,45 @@ class stock_picking(osv.osv):
'state':'draft',
})
if product_qty != 0:
+ price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
defaults = {
'product_qty' : product_qty,
'product_uos_qty': product_qty, #TODO: put correct uos_qty
'picking_id' : new_picking,
'state': 'assigned',
'move_dest_id': False,
- 'price_unit': move.price_unit,
+ 'price_unit': price_unit or 0.0
}
prodlot_id = prodlot_ids[move.id]
if prodlot_id:
defaults.update(prodlot_id=prodlot_id)
move_obj.copy(cr, uid, move.id, defaults)
-
+ if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
+ new_price_unit = move.product_id.standard_price
+ else:
+ new_price_unit = price_unit
move_obj.write(cr, uid, [move.id],
{
'product_qty' : move.product_qty - product_qty,
'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty
+ 'price_unit': new_price_unit or 0.0
})
if new_picking:
move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
for move in complete:
+ price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
+ defaults = {'price_unit': price_unit or 0.0}
if prodlot_ids.get(move.id):
- move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]})
+ defaults.update({'prodlot_id': prodlot_ids[move.id]})
+ move_obj.write(cr, uid, [move.id], defaults)
for move in too_many:
+ price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
product_qty = move_product_qty[move.id]
defaults = {
'product_qty' : product_qty,
'product_uos_qty': product_qty, #TODO: put correct uos_qty
+ 'price_unit': price_unit or 0.0
}
prodlot_id = prodlot_ids.get(move.id)
if prodlot_ids.get(move.id):
@@ -2489,7 +2511,7 @@ class stock_move(osv.osv):
for move in complete:
if prodlot_ids.get(move.id):
- self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)})
+ self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id), 'price_unit': move.product_id.standard_price})
self.action_done(cr, uid, [move.id], context=context)
if move.picking_id.id :
# TOCHECK : Done picking if all moves are done
diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py
index b7c8aa28354..6b0ed010426 100644
--- a/addons/stock/wizard/stock_return_picking.py
+++ b/addons/stock/wizard/stock_return_picking.py
@@ -33,6 +33,7 @@ class stock_return_picking_memory(osv.osv_memory):
'quantity' : fields.float("Quantity", required=True),
'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
'move_id' : fields.many2one('stock.move', "Move"),
+ 'price_unit' : fields.float('Cost Price', digits=(16,2), help="Historical cost price of product")
}
stock_return_picking_memory()
@@ -73,7 +74,7 @@ class stock_return_picking(osv.osv_memory):
for line in pick.move_lines:
qty = line.product_qty - return_history[line.id]
if qty > 0:
- result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id})
+ result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id, 'price_unit': line.price_unit})
if 'product_return_moves' in fields:
res.update({'product_return_moves': result1})
return res
@@ -180,9 +181,10 @@ class stock_return_picking(osv.osv_memory):
'product_qty': new_qty,
'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
new_qty, move.product_uos.id),
- 'picking_id':new_picking, 'state':'draft',
- 'location_id':new_location, 'location_dest_id':move.location_id.id,
- 'date':date_cur,})
+ 'picking_id': new_picking, 'state': 'draft',
+ 'location_id': new_location, 'location_dest_id': move.location_id.id,
+ 'date': date_cur,
+ 'price_unit': move.price_unit})
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
if not returned_lines:
raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
diff --git a/addons/stock/wizard/stock_return_picking_view.xml b/addons/stock/wizard/stock_return_picking_view.xml
index 51431eeee45..876dd3373da 100644
--- a/addons/stock/wizard/stock_return_picking_view.xml
+++ b/addons/stock/wizard/stock_return_picking_view.xml
@@ -18,7 +18,7 @@
-
+
@@ -31,6 +31,7 @@
From 58e403bc2346dd9f39a6f918b771575dc857a9aa Mon Sep 17 00:00:00 2001
From: "ron@tinyerp.com" <>
Date: Tue, 21 Jun 2011 15:48:46 +0530
Subject: [PATCH 2/9] [IMP]stock:Improvement in code
bzr revid: ron@tinyerp.com-20110621101846-1s9azk4jlwkpzwd9
---
addons/stock/stock.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index f6e4d1f08ff..a8b429f4b8b 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1257,7 +1257,7 @@ class stock_picking(osv.osv):
if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
new_price_unit = move.product_id.standard_price
else:
- new_price_unit = price_unit
+ new_price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
move_obj.write(cr, uid, [move.id],
{
'product_qty' : move.product_qty - product_qty,
From 285bbd8dec76a3a44e9d9a73ad1926cfd10be104 Mon Sep 17 00:00:00 2001
From: "ron@tinyerp.com" <>
Date: Mon, 27 Jun 2011 12:17:58 +0530
Subject: [PATCH 3/9] [IMP]stock:fixed=>1) use historical price in
report_stock_move.py instead of product avg price 2)onchange price_unit in
move
bzr revid: ron@tinyerp.com-20110627064758-ahhhzqhvmho7dq1k
---
addons/stock/report/report_stock_move.py | 6 +++---
addons/stock/stock.py | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/addons/stock/report/report_stock_move.py b/addons/stock/report/report_stock_move.py
index 07289a4379a..faa31e98051 100644
--- a/addons/stock/report/report_stock_move.py
+++ b/addons/stock/report/report_stock_move.py
@@ -94,11 +94,11 @@ class report_stock_move(osv.osv):
ELSE 0.0
END AS in_qty,
CASE WHEN sp.type in ('out') THEN
- sum(sm.product_qty * pu.factor) * pt.standard_price
+ sum(sm.product_qty * pu.factor) * sm.price_unit
ELSE 0.0
END AS out_value,
CASE WHEN sp.type in ('in') THEN
- sum(sm.product_qty * pu.factor) * pt.standard_price
+ sum(sm.product_qty * pu.factor) * sm.price_unit
ELSE 0.0
END AS in_value,
min(sm.id) as sm_id,
@@ -133,7 +133,7 @@ class report_stock_move(osv.osv):
sm.id,sp.type, sm.date,sm.address_id,
sm.product_id,sm.state,sm.product_uom,sm.date_expected,
sm.product_id,pt.standard_price, sm.picking_id, sm.product_qty,
- sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id)
+ sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id, sm.price_unit)
AS al
GROUP BY
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index a8b429f4b8b..71be16ec78c 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1769,6 +1769,7 @@ class stock_move(osv.osv):
'product_uom': product.uom_id.id,
'product_uos': uos_id,
'product_qty': 1.00,
+ 'price_unit': product.standard_price,
'product_uos_qty' : self.pool.get('stock.move').onchange_quantity(cr, uid, ids, prod_id, 1.00, product.uom_id.id, uos_id)['value']['product_uos_qty']
}
if not ids:
From 765336878ee75f7960d6cd4d2eed2c04364a7d5f Mon Sep 17 00:00:00 2001
From: "ron@tinyerp.com" <>
Date: Mon, 27 Jun 2011 15:57:39 +0530
Subject: [PATCH 4/9] [IMP]stock:fixed=>use historical price in Inventory
Analysis report if product costing method Avarage method otherwise valuation
depends on current price
bzr revid: ron@tinyerp.com-20110627102739-8faa7dcj052hmb87
---
addons/stock/report/report_stock_move.py | 30 ++++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/addons/stock/report/report_stock_move.py b/addons/stock/report/report_stock_move.py
index faa31e98051..f99a9fbcb05 100644
--- a/addons/stock/report/report_stock_move.py
+++ b/addons/stock/report/report_stock_move.py
@@ -176,11 +176,16 @@ CREATE OR REPLACE view report_stock_inventory AS (
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
m.company_id,
m.state as state, m.prodlot_id as prodlot_id,
- coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0) as value,
- CASE when pt.uom_id = m.product_uom THEN
+ case when (pt.cost_method = 'average') then
+ coalesce(sum(-m.price_unit * m.product_qty)::decimal, 0.0)
+ else
+ coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0)
+ end as value,
+ case when pt.uom_id = m.product_uom then
coalesce(sum(-m.product_qty)::decimal, 0.0)
- ELSE
- coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
+ else
+ coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0)
+ end as product_qty
FROM
stock_move m
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
@@ -191,7 +196,7 @@ CREATE OR REPLACE view report_stock_inventory AS (
LEFT JOIN stock_location l ON (m.location_id=l.id)
GROUP BY
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
- m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id
+ m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id, pt.cost_method
) UNION ALL (
SELECT
-m.id as id, m.date as date,
@@ -199,11 +204,16 @@ CREATE OR REPLACE view report_stock_inventory AS (
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
m.company_id,
m.state as state, m.prodlot_id as prodlot_id,
- coalesce(sum(pt.standard_price * m.product_qty )::decimal, 0.0) as value,
- CASE when pt.uom_id = m.product_uom THEN
+ case when (pt.cost_method = 'average') then
+ coalesce(sum(m.price_unit * m.product_qty)::decimal, 0.0)
+ else
+ coalesce(sum(pt.standard_price * m.product_qty)::decimal, 0.0)
+ end as value,
+ case when pt.uom_id = m.product_uom then
coalesce(sum(m.product_qty)::decimal, 0.0)
- ELSE
- coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
+ else
+ coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0)
+ end as product_qty
FROM
stock_move m
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
@@ -214,7 +224,7 @@ CREATE OR REPLACE view report_stock_inventory AS (
LEFT JOIN stock_location l ON (m.location_dest_id=l.id)
GROUP BY
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
- m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id
+ m.prodlot_id, m.date, m.state, l.usage, m.company_id, pt.uom_id, pt.cost_method
)
);
""")
From ce9f1641c5d61be88a8217f54671e446b5d5c032 Mon Sep 17 00:00:00 2001
From: "Rucha (Open ERP)"
Date: Thu, 11 Aug 2011 18:36:20 +0530
Subject: [PATCH 5/9] [REF]: stock: Improved code
bzr revid: rpa@tinyerp.com-20110811130620-tak9gm38nsj3i88y
---
addons/stock/stock.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 71be16ec78c..ebc304bf1ce 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -1248,7 +1248,7 @@ class stock_picking(osv.osv):
'picking_id' : new_picking,
'state': 'assigned',
'move_dest_id': False,
- 'price_unit': price_unit or 0.0
+ 'price_unit': price_unit
}
prodlot_id = prodlot_ids[move.id]
if prodlot_id:
From b1b6ea82e6cf10d8aeae4f82c6cfd1d2fbf92231 Mon Sep 17 00:00:00 2001
From: "Rucha (Open ERP)"
Date: Thu, 11 Aug 2011 18:38:17 +0530
Subject: [PATCH 6/9] [IMP]: stock: price unit is not stored in the moves when
creating inventory
bzr revid: rpa@tinyerp.com-20110811130817-h5olihkxivphu093
---
addons/stock/stock.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index ebc304bf1ce..0d39c50b949 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -2597,6 +2597,7 @@ class stock_inventory(osv.osv):
'product_uom': line.product_uom.id,
'prodlot_id': lot_id,
'date': inv.date,
+ 'price_unit': line.product_id.standard_price
}
if change > 0:
value.update( {
From 2f04d3a6c435db217dd30bf2b8ebe49eecc13f5b Mon Sep 17 00:00:00 2001
From: "Rucha (Open ERP)"
Date: Thu, 11 Aug 2011 18:39:46 +0530
Subject: [PATCH 7/9] [FIX]: stock: Corrected value while processing pickings
for the products with costing method avg price
bzr revid: rpa@tinyerp.com-20110811130946-02yv7v5i8bbdwrlg
---
addons/stock/wizard/stock_partial_picking.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py
index 421bcae10ba..b3c2c52b59f 100644
--- a/addons/stock/wizard/stock_partial_picking.py
+++ b/addons/stock/wizard/stock_partial_picking.py
@@ -127,7 +127,7 @@ class stock_partial_picking(osv.osv_memory):
if pick_type == 'in':
move_memory.update({
- 'cost' : picking.product_id.standard_price,
+ 'cost' : picking.price_unit,
'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,
})
return move_memory
From d0da0465a3517241f1dcf21be6645496f4fa7270 Mon Sep 17 00:00:00 2001
From: "Rucha (Open ERP)"
Date: Thu, 11 Aug 2011 18:43:49 +0530
Subject: [PATCH 8/9] [FIX]: stock: when returning products if we change the
price it should reflact in the price_unit field too
bzr revid: rpa@tinyerp.com-20110811131349-r0sjbm31oq37e37b
---
addons/stock/wizard/stock_return_picking.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py
index 6b0ed010426..a79251438e5 100644
--- a/addons/stock/wizard/stock_return_picking.py
+++ b/addons/stock/wizard/stock_return_picking.py
@@ -184,7 +184,7 @@ class stock_return_picking(osv.osv_memory):
'picking_id': new_picking, 'state': 'draft',
'location_id': new_location, 'location_dest_id': move.location_id.id,
'date': date_cur,
- 'price_unit': move.price_unit})
+ 'price_unit': data_get.price_unit})
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
if not returned_lines:
raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
From e34c3004d9848280e213eaa70a35a988768a4f6d Mon Sep 17 00:00:00 2001
From: "Rucha (Open ERP)"
Date: Thu, 11 Aug 2011 18:46:18 +0530
Subject: [PATCH 9/9] [IMP]: stock: new field price_unit in return picking
wizard should have precision consistent with price_unit of stock move
(currently its taking precision of account but its improved in bug:
LP:788064)
bzr revid: rpa@tinyerp.com-20110811131618-fmrjeplkqorktmoh
---
addons/stock/wizard/stock_return_picking.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py
index a79251438e5..f7ccc41b479 100644
--- a/addons/stock/wizard/stock_return_picking.py
+++ b/addons/stock/wizard/stock_return_picking.py
@@ -21,7 +21,7 @@
import netsvc
import time
-
+import decimal_precision as dp
from osv import osv,fields
from tools.translate import _
@@ -33,7 +33,7 @@ class stock_return_picking_memory(osv.osv_memory):
'quantity' : fields.float("Quantity", required=True),
'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
'move_id' : fields.many2one('stock.move', "Move"),
- 'price_unit' : fields.float('Cost Price', digits=(16,2), help="Historical cost price of product")
+ 'price_unit' : fields.float('Cost Price', digits_compute=dp.get_precision('Purchase Price'), help="Historical cost price of product")
}
stock_return_picking_memory()