From 6a3d10b60c35e9a7babf5bd07eb641a3b3f039e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 24 Sep 2012 22:17:51 +0200 Subject: [PATCH] Active Record --- __init__.py | 8 ++++++++ company.py | 26 ++++++++++++++++---------- res.py | 17 ++++++++++------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/__init__.py b/__init__.py index 5f6f7fab9e..0074019bc4 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,13 @@ #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 .company import * from .res import * + + +def register(): + Pool.register( + Company, + User, + module='company_work_time', type_='model') diff --git a/company.py b/company.py index 732da26e3b..3206618c77 100644 --- a/company.py +++ b/company.py @@ -1,27 +1,33 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -"Company" -from trytond.model import ModelView, ModelSQL, fields +from trytond.model import fields +from trytond.pool import PoolMeta -class Company(ModelSQL, ModelView): - _name = 'company.company' +__all__ = ['Company'] +__metaclass__ = PoolMeta + + +class Company: + __name__ = 'company.company' hours_per_work_day = fields.Float("Hours per Work Day", required=True) hours_per_work_week = fields.Float("Hours per Work Week", required=True) hours_per_work_month = fields.Float("Hours per Work Month", required=True) hours_per_work_year = fields.Float("Hours per Work Year", required=True) - def default_hours_per_work_day(self): + @staticmethod + def default_hours_per_work_day(): return 8 - def default_hours_per_work_week(self): + @staticmethod + def default_hours_per_work_week(): return 40 - def default_hours_per_work_month(self): + @staticmethod + def default_hours_per_work_month(): return 160 - def default_hours_per_work_year(self): + @staticmethod + def default_hours_per_work_year(): return 1920 - -Company() diff --git a/res.py b/res.py index e0950f60b9..519cc64039 100644 --- a/res.py +++ b/res.py @@ -1,13 +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 +from trytond.pool import PoolMeta -class User(ModelSQL, ModelView): - _name = 'res.user' +__all__ = ['User'] +__metaclass__ = PoolMeta - def _get_preferences(self, user, context_only=False): - res = super(User, self)._get_preferences(user, + +class User: + __name__ = 'res.user' + + @classmethod + def _get_preferences(cls, user, context_only=False): + res = super(User, cls)._get_preferences(user, context_only=context_only) if user.company: res['company_work_time'] = { @@ -17,5 +22,3 @@ class User(ModelSQL, ModelView): 'd': user.company.hours_per_work_day, } return res - -User()