Files
tryton/product.py
T

50 lines
1.7 KiB
Python
Raw Normal View History

2014-12-02 12:55:35 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2013-09-06 22:34:27 +02:00
from sql import Column
from sql.aggregate import Max
from sql.conditionals import Coalesce
from trytond.model import ModelView, ModelSQL, fields
2017-04-01 00:32:16 +02:00
from trytond.pool import Pool, PoolMeta
__all__ = ['ProductCostPrice', 'ProductCostHistory']
2017-04-01 00:32:16 +02:00
2018-06-26 19:11:49 +02:00
class ProductCostPrice(metaclass=PoolMeta):
2017-04-01 00:32:16 +02:00
__name__ = 'product.cost_price'
_history = True
2012-09-24 22:18:02 +02:00
class ProductCostHistory(ModelSQL, ModelView):
'History of Product Cost'
2012-09-24 22:18:02 +02:00
__name__ = 'product.product.cost_history'
product = fields.Many2One('product.product', "Product")
date = fields.DateTime('Date')
cost_price = fields.Numeric('Cost Price')
2012-09-24 22:18:02 +02:00
@classmethod
def __setup__(cls):
super(ProductCostHistory, cls).__setup__()
cls._order.insert(0, ('date', 'DESC'))
2013-09-06 22:34:27 +02:00
@classmethod
def table_query(cls):
2012-09-24 22:18:02 +02:00
pool = Pool()
2017-04-01 00:32:16 +02:00
ProductCostPrice = pool.get('product.cost_price')
history = ProductCostPrice.__table_history__()
return history.select(Max(Column(history, '__id')).as_('id'),
Max(history.create_uid).as_('create_uid'),
Max(history.create_date).as_('create_date'),
Max(history.write_uid).as_('write_uid'),
Max(history.write_date).as_('write_date'),
Coalesce(history.write_date,
history.create_date).as_('date'),
history.product.as_('product'),
2017-04-01 00:32:16 +02:00
history.cost_price.as_('cost_price'),
group_by=(history.id,
Coalesce(history.write_date, history.create_date),
history.product, history.cost_price))
2017-07-26 23:43:23 +02:00
def get_rec_name(self, name):
return str(self.date)