Compare commits

...

2 Commits

Author SHA1 Message Date
Sergio Morillo bfdfb5b9f6 Do not use purchase_unit_price field as it does not exists anymore. 2022-04-18 12:00:28 +02:00
José Miguel Pardo Salar 5ab50e40ba Added date param to get_cost_price method and return purchase cost price.
This commit refs #22596


(cherry picked from commit b0c17e9d91)
2022-04-18 09:31:52 +00:00
1 changed files with 5 additions and 8 deletions

View File

@ -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