From 246b09f42725a7dfebe0580edee8ca9368fd5f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 24 Sep 2012 22:19:48 +0200 Subject: [PATCH] Active Record --- __init__.py | 11 +++++++++ invoice.py | 64 ++++++++++++++++++++++--------------------------- party.py | 17 +++++++------ payment_term.py | 17 +++++++------ 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/__init__.py b/__init__.py index c00489f72c..595b1d745e 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,17 @@ #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 .party import * from .payment_term import * from .invoice import * + + +def register(): + Pool.register( + Party, + Address, + PaymentTerm, + PaymentTermLine, + Invoice, + module='account_invoice_history', type_='model') diff --git a/invoice.py b/invoice.py index ae358ac093..0541dfcc91 100644 --- a/invoice.py +++ b/invoice.py @@ -1,49 +1,43 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. import datetime -import copy -from trytond.model import Model, fields + +from trytond.model import fields +from trytond.pool import PoolMeta + +__all__ = ['Invoice'] +__metaclass__ = PoolMeta -class Invoice(Model): - _name = 'account.invoice' +class Invoice: + __name__ = 'account.invoice' open_date = fields.DateTime('Open Date') - def __init__(self): - super(Invoice, self).__init__() - self.party = copy.copy(self.party) - self.party.datetime_field = 'open_date' - if 'open_date' not in self.party.depends: - self.party.depends = copy.copy(self.party.depends) - self.party.depends.append('open_date') - self.invoice_address = copy.copy(self.invoice_address) - self.invoice_address.datetime_field = 'open_date' - if 'open_date' not in self.invoice_address.depends: - self.invoice_address.depends = copy.copy( - self.invoice_address.depends) - self.invoice_address.depends.append('open_date') - self.payment_term = copy.copy(self.payment_term) - self.payment_term.datetime_field = 'open_date' - if 'open_date' not in self.payment_term.depends: - self.payment_term.depends = copy.copy( - self.payment_term.depends) - self.payment_term.depends.append('open_date') - self._reset_columns() + @classmethod + def __setup__(cls): + super(Invoice, cls).__setup__() + cls.party.datetime_field = 'open_date' + if 'open_date' not in cls.party.depends: + cls.party.depends.append('open_date') + cls.invoice_address.datetime_field = 'open_date' + if 'open_date' not in cls.invoice_address.depends: + cls.invoice_address.depends.append('open_date') + cls.payment_term.datetime_field = 'open_date' + if 'open_date' not in cls.payment_term.depends: + cls.payment_term.depends.append('open_date') - def set_number(self, invoice): - set_open_date = not invoice.number - res = super(Invoice, self).set_number(invoice) + def set_number(self): + set_open_date = not self.number + super(Invoice, self).set_number() if set_open_date: - self.write(invoice.id, { - 'open_date': datetime.datetime.now(), - }) - return res + self.write([self], { + 'open_date': datetime.datetime.now(), + }) - def copy(self, ids, default=None): + @classmethod + def copy(cls, invoices, default=None): if default is None: default = {} default = default.copy() default['open_date'] = None - return super(Invoice, self).copy(ids, default=default) - -Invoice() + return super(Invoice, cls).copy(invoices, default=default) diff --git a/party.py b/party.py index 0d4ead1420..b9011ed9ea 100644 --- a/party.py +++ b/party.py @@ -1,17 +1,16 @@ #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 + +__all__ = ['Party', 'Address'] +__metaclass__ = PoolMeta -class Party(ModelSQL, ModelView): - _name = 'party.party' +class Party: + __name__ = 'party.party' _history = True -Party() - -class Address(ModelSQL, ModelView): - _name = 'party.address' +class Address: + __name__ = 'party.address' _history = True - -Address() diff --git a/payment_term.py b/payment_term.py index 9f9be07041..54a5e69dcd 100644 --- a/payment_term.py +++ b/payment_term.py @@ -1,17 +1,16 @@ #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 + +__all__ = ['PaymentTerm', 'PaymentTermLine'] +__metaclass__ = PoolMeta -class PaymentTerm(ModelSQL, ModelView): - _name = 'account.invoice.payment_term' +class PaymentTerm: + __name__ = 'account.invoice.payment_term' _history = True -PaymentTerm() - -class PaymentTermLine(ModelSQL, ModelView): - _name = 'account.invoice.payment_term.line' +class PaymentTermLine: + __name__ = 'account.invoice.payment_term.line' _history = True - -PaymentTermLine()