From 834bf93d0a728021df7d52a17cfc07b7cfc2499f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 24 Sep 2012 22:18:20 +0200 Subject: [PATCH] Active Record --- __init__.py | 7 +++++++ stock.py | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/__init__.py b/__init__.py index 7202dc7e2f..1b895abd54 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,11 @@ #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 Pool from .stock import * + + +def register(): + Pool.register( + Location, + module='stock_location_sequence', type_='model') diff --git a/stock.py b/stock.py index 952eb7bdd7..c0783ffba2 100644 --- a/stock.py +++ b/stock.py @@ -1,14 +1,18 @@ #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.model import ModelView, ModelSQL, fields +from trytond.model import fields from trytond.pyson import Not, Eval, Bool from trytond.transaction import Transaction from trytond.backend import TableHandler +from trytond.pool import PoolMeta + +__all__ = ['Location'] +__metaclass__ = PoolMeta -class Location(ModelSQL, ModelView): +class Location: "Stock Location" - _name = 'stock.location' + __name__ = 'stock.location' sequence = fields.Integer('Sequence', order_field='(%(table)s.sequence IS NULL) %(order)s, ' '%(table)s.sequence %(order)s', @@ -17,17 +21,17 @@ class Location(ModelSQL, ModelView): }, depends=['active']) - def __init__(self): - super(Location, self).__init__() - self._order.insert(0, ('sequence', 'ASC')) + @classmethod + def __setup__(cls): + super(Location, cls).__setup__() + cls._order.insert(0, ('sequence', 'ASC')) - def init(self, module_name): + @classmethod + def __register__(cls, module_name): cursor = Transaction().cursor - table = TableHandler(cursor, self, module_name) + table = TableHandler(cursor, cls, module_name) - super(Location, self).init(module_name) + super(Location, cls).__register__(module_name) # Migration from 2.4: drop required on sequence table.not_null_action('sequence', action='remove') - -Location()