~eduardo-bayardo-bias/openobject-addons/bias_trunk_v10

« back to all changes in this revision

Viewing changes to stock_income_cost/models/stock.py

  • Committer: Eduardo Bayardo
  • Date: 2017-08-02 00:20:24 UTC
  • Revision ID: eduardo.bayardo@bias.com.mx-20170802002024-kjgutwl4n8090e3c
init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
from odoo import models, fields, api
 
4
 
 
5
 
 
6
class StockMove(models.Model):
 
7
    _inherit = 'stock.move'
 
8
 
 
9
    @api.multi
 
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()
 
14
        code = False
 
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
 
19
 
 
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() )
 
30
                # CORRECTION: 
 
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})
 
34
                return price_unit
 
35
            return self.price_unit
 
36
        return super(StockMove, self).get_price_unit()
 
37
 
 
38