Guest User

Untitled

a guest
Nov 21st, 2012
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from trytond.model import ModelView, ModelSQL, fields
  2. from datetime import date, datetime
  3. from trytond.pool import Pool
  4. from trytond.transaction import Transaction
  5. import logging
  6.  
  7. __all__ = ['People']
  8.  
  9.  
  10. class People(ModelSQL, ModelView):
  11. "People"
  12. __name__ = "people.people"
  13. __description__ = __doc__
  14.  
  15. #TODO uniq id
  16. asynctoid = fields.Char('Asyncto Id', required=False, select=False, readonly=True)
  17. aurovillename = fields.Char('Auroville name', required=True, translate=False, select=True)
  18. name = fields.Char('Given name', translate=False, select=True)
  19. surname = fields.Char('Surname', translate=False, select=True)
  20. telephone = fields.Char('Phone number', translate=False)
  21. email = fields.Char('Email', translate=False, select=True)
  22. contactperson = fields.Char('Contact person', translate=False, select=True)
  23. masterlistid = fields.Integer('Masterlist ID', readonly=True, select=True)
  24.  
  25. date_birth = fields.Date('Date of birth')
  26.  
  27. sex = fields.Selection([
  28. ('Male', 'Male'),
  29. ('Female', 'Female'),
  30. ], 'Sex', required=True)
  31.  
  32. photo = fields.Binary('Picture')
  33.  
  34. nationality = fields.Many2One('country.nationality', 'Nationality', select=True)
  35. age = fields.Function(fields.Integer('Age'),'get_people_age')
  36.  
  37.  
  38. status = fields.Selection([
  39. ('Aurovilian', 'Aurovilian'),
  40. ('Newcomer', 'Newcomer'),
  41. ('Pre-Newcomer', 'Pre-Newcomer'),
  42. ('Volunteer', 'Volunteer'),
  43. ('Youth', 'Youth'),
  44. ('Child', 'Child'),
  45. ('Friend of Auroville', 'Friend of Auroville'),
  46. ('Guest', 'Guest'),
  47. ], 'Status', required=True)
  48.  
  49. user_id = fields.Many2One('res.user', 'User', required=True, readonly=True)
  50.  
  51.  
  52. @classmethod
  53. def __setup__(cls):
  54. super(People, cls).__setup__()
  55. cls._order.insert(0, ('masterlistid', 'ASC'))
  56.  
  57.  
  58. def get_people_age(self, ids, name):
  59.  
  60. today = date.today()
  61. res = {}
  62. for human in self.browse(ids):
  63. born = human.date_birth
  64. if born:
  65. res[human.id] = today.year - born.year - int((today.month, today.day) < (born.month, born.day))
  66. else:
  67. res[human.id] = 0
  68. return res
  69.  
  70.  
  71. def default_user_id(self):
  72. user_obj = Pool().get('res.user')
  73. user = user_obj.browse(Transaction().user)
  74. return int(user.id)
  75.  
  76. def default_sex(self):
  77. return 'Male'
  78.  
  79. def default_status(self):
  80. return 'Aurovilian'
  81.  
  82. def asyncto_sync(self):
  83. log = logging.getLogger('logfile')
  84. log.warn('Asyncto People sync')
  85. try:
  86. asyncto_obj = Pool().get('auroville.asyncto')
  87. people_obj = Pool().get('auroville.people')
  88. asyncto_ids = asyncto_obj.search([])
  89. for item in asyncto_obj.browse(asyncto_ids):
  90. people_ids = people_obj.search([('asynctoid', '=', item.asynctoid),])
  91. data = {'asynctoid' : item.asynctoid, 'aurovillename' : item.aurovillename, 'name' : item.name, 'surname' : item.surname,
  92. 'telephone' : item.telephone, 'email' : item.email, 'contactperson' : item.contactperson,
  93. 'masterlistid' : int(item.masterlistid)}
  94. if people_ids:
  95. people_obj.write(people_ids, data)
  96. else:
  97. people_obj.create(data)
  98.  
  99. # Community
  100.  
  101.  
  102. except Exception as e:
  103. log.error(e)
  104. #People()
RAW Paste Data