1
# -*- coding: utf-8 -*-
3
from odoo import models, fields, api
6
class StockMove(models.Model):
7
_inherit = 'stock.move'
10
def get_price_unit(self):
11
""" Returns the unit price to store on the quant """
12
context = self.env.context
13
date = fields.Datetime.now()
15
if context.get('default_picking_type_id'):
16
code = self.env['stock.picking.type'].browse(context['default_picking_type_id']).code
17
if (code == 'incoming') and (context.get('active_model') in ['stock.picking.type','stock.picking']):
18
date = self.picking_id.min_date
20
if self.purchase_line_id:
21
order = self.purchase_line_id.order_id
22
#if the currency of the PO is different than the company one, the price_unit on the move must be reevaluated
23
#(was created at the rate of the PO confirmation, but must be valuated at the rate of stock move execution)
24
if order.currency_id != self.company_id.currency_id:
25
# ORIGIN: ./addons/purchase/stock.py @get_price_unit()
26
#we don't pass the move.date in the compute() for the currency rate on purpose because
27
# 1) get_price_unit() is supposed to be called only through move.action_done(),
28
# 2) the move hasn't yet the correct date (currently it is the expected date, after
29
# completion of action_done() it will be now() )
31
# Now we pass the move.min_date (Scheduled Date) in order to get the proprer price_unit
32
price_unit = self.purchase_line_id.with_context(date=date)._get_stock_move_price_unit()
33
self.write({'price_unit': price_unit})
35
return self.price_unit
36
return super(StockMove, self).get_price_unit()