Compare commits
2 Commits
907760db95
...
bfdfb5b9f6
Author | SHA1 | Date |
---|---|---|
Sergio Morillo | bfdfb5b9f6 | |
José Miguel Pardo Salar | 5ab50e40ba |
13
stock.py
13
stock.py
|
@ -3,9 +3,6 @@
|
|||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import fields
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Lot']
|
||||
|
||||
|
||||
class Lot(metaclass=PoolMeta):
|
||||
|
@ -14,18 +11,18 @@ class Lot(metaclass=PoolMeta):
|
|||
cost_price = fields.Function(fields.Numeric(
|
||||
'Cost Price', digits=price_digits), 'get_cost_price')
|
||||
|
||||
def get_cost_price(self, name=None):
|
||||
def get_cost_price(self, name=None, date=None):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
date = Transaction().context.get('date') or Date.today()
|
||||
if not date:
|
||||
date = Date.today()
|
||||
moves = Move.search([
|
||||
('lot', '=', self),
|
||||
('state', 'in', ['assigned', 'done']),
|
||||
('origin', 'like', 'purchase.line,%'),
|
||||
('effective_date', '<=', date)
|
||||
])
|
||||
|
||||
], order=[('effective_date', 'DESC')])
|
||||
if moves:
|
||||
return moves[0].unit_price
|
||||
return moves[0].origin.unit_price
|
||||
|
|
Loading…
Reference in New Issue