From 2314ef1d7f5cf8dc3175b183e1cbaa2675a50ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 1 Apr 2017 00:32:16 +0200 Subject: [PATCH] Remove Property fields issue2349 review35331002 --- __init__.py | 3 +-- ir.py | 11 ----------- product.py | 48 ++++++++++++++++++++++-------------------------- 3 files changed, 23 insertions(+), 39 deletions(-) delete mode 100644 ir.py diff --git a/__init__.py b/__init__.py index c97aa3e6a5..66114a206c 100644 --- a/__init__.py +++ b/__init__.py @@ -2,13 +2,12 @@ # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -from .ir import * from .product import * def register(): Pool.register( - Property, + ProductCostPrice, ProductCostHistory, module='product_cost_history', type_='model') Pool.register( diff --git a/ir.py b/ir.py deleted file mode 100644 index 8cdaabe797..0000000000 --- a/ir.py +++ /dev/null @@ -1,11 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. -from trytond.pool import PoolMeta - -__all__ = ['Property'] - - -class Property: - __metaclass__ = PoolMeta - __name__ = 'ir.property' - _history = True diff --git a/product.py b/product.py index 6c811aa2d2..85a318f6c3 100644 --- a/product.py +++ b/product.py @@ -3,15 +3,20 @@ from sql import Column from sql.aggregate import Max from sql.conditionals import Coalesce -from sql.functions import Trim, Substring from trytond.model import ModelView, ModelSQL, fields from trytond.wizard import Wizard, StateAction from trytond.pyson import PYSONEncoder -from trytond.pool import Pool +from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction -__all__ = ['ProductCostHistory', 'OpenProductCostHistory'] +__all__ = ['ProductCostPrice', 'ProductCostHistory', 'OpenProductCostHistory'] + + +class ProductCostPrice: + __metaclass__ = PoolMeta + __name__ = 'product.cost_price' + _history = True class ProductCostHistory(ModelSQL, ModelView): @@ -30,29 +35,20 @@ class ProductCostHistory(ModelSQL, ModelView): @classmethod def table_query(cls): pool = Pool() - Property = pool.get('ir.property') - Field = pool.get('ir.model.field') - property_history = Property.__table_history__() - field = Field.__table__() - return property_history.join(field, - condition=field.id == property_history.field - ).select(Max(Column(property_history, '__id')).as_('id'), - Max(property_history.create_uid).as_('create_uid'), - Max(property_history.create_date).as_('create_date'), - Max(property_history.write_uid).as_('write_uid'), - Max(property_history.write_date).as_('write_date'), - Coalesce(property_history.write_date, - property_history.create_date).as_('date'), - Trim(Substring(property_history.res, ',.*'), 'LEADING', ',' - ).cast(cls.template.sql_type().base).as_('template'), - Trim(property_history.value, 'LEADING', ',' - ).cast(cls.cost_price.sql_type().base).as_('cost_price'), - where=(field.name == 'cost_price') - & property_history.res.like('product.template,%'), - group_by=(property_history.id, - Coalesce(property_history.write_date, - property_history.create_date), - property_history.res, property_history.value)) + 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.template.as_('template'), + history.cost_price.as_('cost_price'), + group_by=(history.id, + Coalesce(history.write_date, history.create_date), + history.template, history.cost_price)) class OpenProductCostHistory(Wizard):