[FIX] stock/purchase: dates and currency rates

Use the currency rate of the purchase date instead of the one of at the reception time (opw 610430)
This commit is contained in:
qdp-odoo 2014-09-17 18:04:41 +02:00 committed by Martin Trigaux
parent 3a50d4b35b
commit 8973217ea7
4 changed files with 45 additions and 6 deletions

View File

@ -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):

View File

@ -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

View File

@ -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))

View File

@ -26,10 +26,11 @@
<field name="prodlot_id" domain="[('product_id', '=', product_id)]" invisible="context.get('hide_tracking',False)" attrs="{'required':[('tracking','=',True), ('quantity', '!=', 0)]}" groups="stock.group_production_lot" context="{'default_product_id':product_id}"/>
<!-- Removed as this feature is not logic: price must be updated upon reception of invoice -->
<field name="update_cost" invisible="1"/>
<field name="cost" invisible="1"/>
<field name="currency" invisible="1"/>
<field name="cost" groups="base.group_multi_currency"/>
<field name="currency" readonly="1" groups="base.group_multi_currency"/>
</tree>
</field>
<field name="help_text" groups="base.group_multi_currency" class="oe_grey"/>
<footer>
<button name="do_partial" string="_Transfer" type="object" class="oe_highlight"/>
or