diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index d258eee7431..5d56d3cb31a 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -643,6 +643,10 @@ class purchase_order(osv.osv):
}
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
+ price_unit = order_line.price_unit
+ if order.currency_id.id != order.company_id.currency_id.id:
+ #we don't round the price_unit, as we may want to store the standard price with more digits than allowed by the currency
+ price_unit = self.pool.get('res.currency').compute(cr, uid, order.currency_id.id, order.company_id.currency_id.id, price_unit, round=False, context=context)
return {
'name': order_line.name or '',
'product_id': order_line.product_id.id,
@@ -661,7 +665,7 @@ class purchase_order(osv.osv):
'type':'in',
'purchase_line_id': order_line.id,
'company_id': order.company_id.id,
- 'price_unit': order_line.price_unit
+ 'price_unit': price_unit
}
def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, context=None):
diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py
index 24df0b5eaa0..fc9c5cc7940 100644
--- a/addons/purchase/stock.py
+++ b/addons/purchase/stock.py
@@ -20,6 +20,7 @@
##############################################################################
from openerp.osv import fields, osv
+from openerp.tools.translate import _
class stock_move(osv.osv):
_inherit = 'stock.move'
@@ -127,11 +128,30 @@ class stock_partial_picking(osv.osv_memory):
# Overridden to inject the purchase price as true 'cost price' when processing
# incoming pickings.
def _product_cost_for_average_update(self, cr, uid, move):
- if move.picking_id.purchase_id and move.purchase_line_id:
- return {'cost': move.purchase_line_id.price_unit,
- 'currency': move.picking_id.purchase_id.pricelist_id.currency_id.id}
+ if move.purchase_line_id and move.purchase_line_id and move.purchase_line_id.invoice_lines:
+ cost = move.price_unit
+ for inv_line in move.purchase_line_id.invoice_lines:
+ if inv_line.invoice_id.state not in ('draft', 'cancel'):
+ inv_currency = inv_line.invoice_id.currency_id.id
+ company_currency = inv_line.invoice_id.company_id.currency_id.id
+ cost = self.pool.get('res.currency').compute(cr, uid, inv_currency, company_currency, inv_line.price_unit, round=False, context={'date': inv_line.invoice_id.date_invoice})
+ return {'cost': cost, 'currency': company_currency}
return super(stock_partial_picking, self)._product_cost_for_average_update(cr, uid, move)
+ def __get_help_text(self, cursor, user, picking_id, context=None):
+ picking = self.pool.get('stock.picking').browse(cursor, user, picking_id, context=context)
+ if picking.purchase_id:
+ text = _("The proposed cost is made based on %s")
+ value = _("Purchase Order %s") % picking.purchase_id.name
+ if picking.purchase_id.pricelist_id.currency_id != picking.purchase_id.company_id.currency_id:
+ value += _(" (currency rate of purchase order taken)")
+ if any([x.state not in ('draft', 'cancel') for x in picking.purchase_id.invoice_ids]):
+ value = _("Invoices made on Purchase Order %s") % (picking.purchase_id.name)
+ if picking.purchase_id.pricelist_id.currency_id != picking.purchase_id.company_id.currency_id:
+ value += _(" (currency rate of invoices taken)")
+ return text % value
+ return super(stock_partial_picking, self).__get_help_text(cursor, user, picking_id, context=context)
+
# Redefinition of the new field in order to update the model stock.picking.in in the orm
# FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as
# the bug is fixed
diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py
index 6d41deeb85e..4d364490943 100644
--- a/addons/stock/wizard/stock_partial_picking.py
+++ b/addons/stock/wizard/stock_partial_picking.py
@@ -75,11 +75,23 @@ class stock_partial_picking(osv.osv_memory):
res[wizard.id] = any([not(x.tracking) for x in wizard.move_ids])
return res
+ def __get_help_text(self, cursor, user, picking_id, context=None):
+ text = _("The proposed cost is made based on %s")
+ value = _("standard prices set on the products")
+ return text % value
+
+ def _get_help_text(self, cursor, user, ids, name, arg, context=None):
+ res = {}
+ for wiz in self.browse(cursor, user, ids, context=context):
+ res[wiz.id] = self.__get_help_text(cursor, user, wiz.picking_id.id, context=context)
+ return res
+
_columns = {
'date': fields.datetime('Date', required=True),
'move_ids' : fields.one2many('stock.partial.picking.line', 'wizard_id', 'Product Moves'),
'picking_id': fields.many2one('stock.picking', 'Picking', required=True, ondelete='CASCADE'),
'hide_tracking': fields.function(_hide_tracking, string='Tracking', type='boolean', help='This field is for internal purpose. It is used to decide if the column production lot has to be shown on the moves or not.'),
+ 'help_text': fields.function(_get_help_text, string='Note', type='char'),
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
@@ -122,6 +134,7 @@ class stock_partial_picking(osv.osv_memory):
res.update(move_ids=moves)
if 'date' in fields:
res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
+ res['help_text'] = self.__get_help_text(cr, uid, picking_id, context=context)
return res
def _product_cost_for_average_update(self, cr, uid, move):
@@ -150,6 +163,7 @@ class stock_partial_picking(osv.osv_memory):
'move_id' : move.id,
'location_id' : move.location_id.id,
'location_dest_id' : move.location_dest_id.id,
+ 'currency': move.picking_id.company_id.currency_id.id,
}
if move.picking_id.type == 'in' and move.product_id.cost_method == 'average':
partial_move.update(update_cost=True, **self._product_cost_for_average_update(cr, uid, move))
diff --git a/addons/stock/wizard/stock_partial_picking_view.xml b/addons/stock/wizard/stock_partial_picking_view.xml
index 4e0bf302bc6..ef474bb9921 100644
--- a/addons/stock/wizard/stock_partial_picking_view.xml
+++ b/addons/stock/wizard/stock_partial_picking_view.xml
@@ -26,10 +26,11 @@
-
-
+
+
+