mirror of
https://gitlab.com/datalifeit/trytond-stock_lot_cost_price
synced 2023-12-14 05:33:05 +01:00
Added date param to get_cost_price method and return purchase cost price.
This commit refs #22596
This commit is contained in:
parent
8f1f4ba4f0
commit
b0c17e9d91
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].purchase_unit_price
|
||||
|
|
Loading…
Reference in a new issue