[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:
parent
3a50d4b35b
commit
8973217ea7
|
@ -643,6 +643,10 @@ class purchase_order(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
|
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 {
|
return {
|
||||||
'name': order_line.name or '',
|
'name': order_line.name or '',
|
||||||
'product_id': order_line.product_id.id,
|
'product_id': order_line.product_id.id,
|
||||||
|
@ -661,7 +665,7 @@ class purchase_order(osv.osv):
|
||||||
'type':'in',
|
'type':'in',
|
||||||
'purchase_line_id': order_line.id,
|
'purchase_line_id': order_line.id,
|
||||||
'company_id': order.company_id.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):
|
def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, context=None):
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, osv
|
||||||
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
class stock_move(osv.osv):
|
class stock_move(osv.osv):
|
||||||
_inherit = 'stock.move'
|
_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
|
# Overridden to inject the purchase price as true 'cost price' when processing
|
||||||
# incoming pickings.
|
# incoming pickings.
|
||||||
def _product_cost_for_average_update(self, cr, uid, move):
|
def _product_cost_for_average_update(self, cr, uid, move):
|
||||||
if move.picking_id.purchase_id and move.purchase_line_id:
|
if move.purchase_line_id and move.purchase_line_id and move.purchase_line_id.invoice_lines:
|
||||||
return {'cost': move.purchase_line_id.price_unit,
|
cost = move.price_unit
|
||||||
'currency': move.picking_id.purchase_id.pricelist_id.currency_id.id}
|
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)
|
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
|
# 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
|
# FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as
|
||||||
# the bug is fixed
|
# the bug is fixed
|
||||||
|
|
|
@ -75,11 +75,23 @@ class stock_partial_picking(osv.osv_memory):
|
||||||
res[wizard.id] = any([not(x.tracking) for x in wizard.move_ids])
|
res[wizard.id] = any([not(x.tracking) for x in wizard.move_ids])
|
||||||
return res
|
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 = {
|
_columns = {
|
||||||
'date': fields.datetime('Date', required=True),
|
'date': fields.datetime('Date', required=True),
|
||||||
'move_ids' : fields.one2many('stock.partial.picking.line', 'wizard_id', 'Product Moves'),
|
'move_ids' : fields.one2many('stock.partial.picking.line', 'wizard_id', 'Product Moves'),
|
||||||
'picking_id': fields.many2one('stock.picking', 'Picking', required=True, ondelete='CASCADE'),
|
'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.'),
|
'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):
|
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)
|
res.update(move_ids=moves)
|
||||||
if 'date' in fields:
|
if 'date' in fields:
|
||||||
res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
|
res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
|
||||||
|
res['help_text'] = self.__get_help_text(cr, uid, picking_id, context=context)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _product_cost_for_average_update(self, cr, uid, move):
|
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,
|
'move_id' : move.id,
|
||||||
'location_id' : move.location_id.id,
|
'location_id' : move.location_id.id,
|
||||||
'location_dest_id' : move.location_dest_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':
|
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))
|
partial_move.update(update_cost=True, **self._product_cost_for_average_update(cr, uid, move))
|
||||||
|
|
|
@ -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}"/>
|
<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 -->
|
<!-- Removed as this feature is not logic: price must be updated upon reception of invoice -->
|
||||||
<field name="update_cost" invisible="1"/>
|
<field name="update_cost" invisible="1"/>
|
||||||
<field name="cost" invisible="1"/>
|
<field name="cost" groups="base.group_multi_currency"/>
|
||||||
<field name="currency" invisible="1"/>
|
<field name="currency" readonly="1" groups="base.group_multi_currency"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="help_text" groups="base.group_multi_currency" class="oe_grey"/>
|
||||||
<footer>
|
<footer>
|
||||||
<button name="do_partial" string="_Transfer" type="object" class="oe_highlight"/>
|
<button name="do_partial" string="_Transfer" type="object" class="oe_highlight"/>
|
||||||
or
|
or
|
||||||
|
|
Loading…
Reference in New Issue