Reviewers: ,


Please review this at http://codereview.tryton.org/393002/

Affected files:
  M __init__.py
  M address.py
  M party.py


Index: __init__.py
===================================================================

--- 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 .party import *
 from .address import *
+
+
+def register():
+    Pool.register(
+        Party,
+        Address,
+        module='party_siret', type_='model')

Index: address.py
===================================================================

--- a/address.py
+++ b/address.py
@@ -1,45 +1,42 @@
 #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 Model, fields
+from trytond.model import fields
 from trytond.pyson import Eval
+from trytond.pool import PoolMeta
 from . import luhn

+__all__ = ['Address']
+__metaclass__ = PoolMeta

-class Address(Model):
-    _name = 'party.address'
+
+class Address:
+    __name__ = 'party.address'

     siret_nic = fields.Char('SIRET NIC', select=True, states={
             'readonly': ~Eval('active', True),
             }, size=5, depends=['active'])
     siret = fields.Function(fields.Char('SIRET'), 'get_siret')

-    def __init__(self):
-        super(Address, self).__init__()
-        self._constraints += [
+    @classmethod
+    def __setup__(cls):
+        super(Address, cls).__setup__()
+        cls._constraints += [
             ('check_siret', 'invalid_siret'),
-        ]
-        self._error_messages.update({
-            'invalid_siret': 'Invalid SIRET number!',
-        })
+            ]
+        cls._error_messages.update({
+                'invalid_siret': 'Invalid SIRET number!',
+                })

-    def get_siret(self, ids, name):
-        res = {}
-        for address in self.browse(ids):
-            if address.party.siren and address.siret_nic:
-                res[address.id] = address.party.siren + address.siret_nic
-            else:
-                res[address.id] = ''
-        return res
+    def get_siret(self, name):
+        if self.party.siren and self.siret_nic:
+            return self.party.siren + self.siret_nic

-    def check_siret(self, ids):
+    def check_siret(self):
         '''
         Check validity of SIRET
         '''
-        for address in self.browse(ids):
-            if address.siret:
-                if (len(address.siret) != 14
-                        or not luhn.validate(address.siret)):
-                    return False
+        if self.siret:
+            if (len(self.siret) != 14
+                    or not luhn.validate(self.siret)):
+                return False
         return True
-
-Address()

Index: party.py
===================================================================

--- a/party.py
+++ b/party.py
@@ -1,34 +1,36 @@
 #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 Model, fields
+from trytond.model import fields
 from trytond.pyson import Eval
+from trytond.pool import PoolMeta
 from . import luhn

+__all__ = ['Party']
+__metaclass__ = PoolMeta

-class Party(Model):
-    _name = 'party.party'
+
+class Party:
+    __name__ = 'party.party'

     siren = fields.Char('SIREN', select=True, states={
             'readonly': ~Eval('active', True),
             }, size=9, depends=['active'])

-    def __init__(self):
-        super(Party, self).__init__()
-        self._constraints += [
+    @classmethod
+    def __setup__(cls):
+        super(Party, cls).__setup__()
+        cls._constraints += [
             ('check_siren', 'invalid_siren'),
-        ]
-        self._error_messages.update({
-            'invalid_siren': 'Invalid SIREN number!',
-        })
+            ]
+        cls._error_messages.update({
+                'invalid_siren': 'Invalid SIREN number!',
+                })

-    def check_siren(self, ids):
+    def check_siren(self):
         '''
         Check validity of SIREN
         '''
-        for party in self.browse(ids):
-            if party.siren:
-                if len(party.siren) != 9 or not luhn.validate(party.siren):
-                    return False
+        if self.siren:
+            if len(self.siren) != 9 or not luhn.validate(self.siren):
+                return False
         return True
-
-Party()



--
[email protected] mailing list

Reply via email to