diff --git a/product.py b/product.py index ede4852ecd..ca70d506ee 100644 --- a/product.py +++ b/product.py @@ -2,11 +2,11 @@ # this repository contains the full copyright notices and license terms. import datetime -from sql import Literal, Null +from sql import Literal from sql.aggregate import Count -from sql.conditionals import Case -from trytond.model import ModelView, ModelSQL, MatchMixin, fields +from trytond.model import ModelView, ModelSQL, MatchMixin, fields, \ + sequence_ordered from trytond.pyson import Eval, If from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction @@ -157,7 +157,7 @@ class Product: return prices -class ProductSupplier(ModelSQL, ModelView, MatchMixin): +class ProductSupplier(sequence_ordered(), ModelSQL, ModelView, MatchMixin): 'Product Supplier' __name__ = 'purchase.product_supplier' product = fields.Many2One('product.template', 'Product', required=True, @@ -166,7 +166,6 @@ class ProductSupplier(ModelSQL, ModelView, MatchMixin): ondelete='CASCADE', select=True) name = fields.Char('Name', size=None, translate=True, select=True) code = fields.Char('Code', size=None, select=True) - sequence = fields.Integer('Sequence') prices = fields.One2Many('purchase.product_supplier.price', 'product_supplier', 'Prices') company = fields.Many2One('company.company', 'Company', required=True, @@ -179,11 +178,6 @@ class ProductSupplier(ModelSQL, ModelView, MatchMixin): currency = fields.Many2One('currency.currency', 'Currency', required=True, ondelete='RESTRICT') - @classmethod - def __setup__(cls): - super(ProductSupplier, cls).__setup__() - cls._order.insert(0, ('sequence', 'ASC')) - @classmethod def __register__(cls, module_name): TableHandler = backend.get('TableHandler') @@ -236,11 +230,6 @@ class ProductSupplier(ModelSQL, ModelView, MatchMixin): where=sql_table.id == id_)) table.drop_column('delivery_time') - @staticmethod - def order_sequence(tables): - table, _ = tables[None] - return [Case((table.sequence == Null, 0), else_=1), table.sequence] - @staticmethod def default_company(): return Transaction().context.get('company') @@ -314,7 +303,8 @@ class ProductSupplier(ModelSQL, ModelView, MatchMixin): } -class ProductSupplierPrice(ModelSQL, ModelView, MatchMixin): +class ProductSupplierPrice( + sequence_ordered(), ModelSQL, ModelView, MatchMixin): 'Product Supplier Price' __name__ = 'purchase.product_supplier.price' product_supplier = fields.Many2One('purchase.product_supplier', @@ -322,12 +312,6 @@ class ProductSupplierPrice(ModelSQL, ModelView, MatchMixin): quantity = fields.Float('Quantity', required=True, help='Minimal quantity') unit_price = fields.Numeric('Unit Price', required=True, digits=price_digits) - sequence = fields.Integer('Sequence') - - @classmethod - def __setup__(cls): - super(ProductSupplierPrice, cls).__setup__() - cls._order.insert(0, ('sequence', 'ASC')) @classmethod def __register__(cls, module_name): @@ -345,11 +329,6 @@ class ProductSupplierPrice(ModelSQL, ModelView, MatchMixin): cursor.execute(*sql_table.update( [sql_table.sequence], [sql_table.quantity])) - @staticmethod - def order_sequence(tables): - table, _ = tables[None] - return [Case((table.sequence == Null, 0), else_=1), table.sequence] - @staticmethod def default_quantity(): return 0.0 diff --git a/purchase.py b/purchase.py index 0818991b7f..4907e4b616 100644 --- a/purchase.py +++ b/purchase.py @@ -8,9 +8,9 @@ from sql import Table, Literal, Null from sql.functions import Overlay, Position from sql.aggregate import Count from sql.operators import Concat -from sql.conditionals import Case -from trytond.model import Workflow, ModelView, ModelSQL, fields +from trytond.model import Workflow, ModelView, ModelSQL, fields, \ + sequence_ordered from trytond.modules.company import CompanyReport from trytond.wizard import Wizard, StateAction, StateView, StateTransition, \ Button @@ -847,7 +847,7 @@ class PurchaseRecreadtedInvoice(ModelSQL): ondelete='RESTRICT', select=True, required=True) -class PurchaseLine(ModelSQL, ModelView): +class PurchaseLine(sequence_ordered(), ModelSQL, ModelView): 'Purchase Line' __name__ = 'purchase.line' _rec_name = 'description' @@ -858,7 +858,6 @@ class PurchaseLine(ModelSQL, ModelView): & Bool(Eval('purchase'))), }, depends=['purchase_state']) - sequence = fields.Integer('Sequence') type = fields.Selection([ ('line', 'Line'), ('subtotal', 'Subtotal'), @@ -969,7 +968,6 @@ class PurchaseLine(ModelSQL, ModelView): @classmethod def __setup__(cls): super(PurchaseLine, cls).__setup__() - cls._order.insert(0, ('sequence', 'ASC')) cls._error_messages.update({ 'supplier_location_required': ('Purchase "%(purchase)s" ' 'misses the supplier location for line "%(line)s".'), @@ -997,11 +995,6 @@ class PurchaseLine(ModelSQL, ModelView): # Migration from 2.4: drop required on sequence table.not_null_action('sequence', action='remove') - @staticmethod - def order_sequence(tables): - table, _ = tables[None] - return [Case((table.sequence == Null, 0), else_=1), table.sequence] - @staticmethod def default_type(): return 'line'