top.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (c) 2013 Acysos S.L. (http://acysos.com) All Rights Reserved.
  6. # Ignacio Ibeas <ignacio@acysos.com>
  7. # Daniel Pascal <daniel@acysos.com>
  8. # $Id$
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. from openerp import models, fields, api
  25. TYPES = [('unlimited', 'unlimited'),
  26. ('flat', 'Flat'),
  27. ('shop', 'Shop'),
  28. ('premise', 'Premise'),
  29. ('chalet', 'Chalet'),
  30. ('house', 'Town House'),
  31. ('office', 'Office'),
  32. ('premise-office', 'Premise-Office'),
  33. ('industrial_unit', 'Industrial Unit'),
  34. ('hotel_industry', 'Hotel Industry'),
  35. ('parking', 'Parking'),
  36. ('box_room', 'Box room'),
  37. ('land', 'Land')]
  38. class real_estate_zone(models.Model):
  39. _name = 'real.estate.zone'
  40. name = fields.Char('Zone', required=True, size=64)
  41. city_id = fields.Many2one(
  42. 'res.better.zip', 'Location', required=False,
  43. help='Usa el nombre o el C.P para buscar la localización')
  44. _order = "name"
  45. class real_estate_heating(models.Model):
  46. _name = 'real.estate.heating'
  47. name = fields.Char('Heating', required=True, size=64)
  48. _order = "name"
  49. class real_estate_hotwater(models.Model):
  50. _name = 'real.estate.hotwater'
  51. name = fields.Char('Hot Water', required=True, size=64)
  52. _order = "name"
  53. class real_estate_land_type(models.Model):
  54. _name = 'real.estate.land.type'
  55. name = fields.Char('Land Type', required=True, size=64)
  56. _order = "name"
  57. class real_estate_land_state(models.Model):
  58. _name = 'real.estate.land.state'
  59. name = fields.Char('Land State', required=True, size=64)
  60. _order = "name"
  61. class real_estate_subtype(models.Model):
  62. _name = 'real.estate.subtype'
  63. name = fields.Char('Subtype', required=True, size=64)
  64. type = fields.Selection(TYPES, string='Top Type', required=True,
  65. select=True)
  66. _order = "name"
  67. class real_estate_top_subdivision(models.Model):
  68. _name = 'real.estate.top.subsivision'
  69. _description = 'Top subdivision that can be rented individually'
  70. name = fields.Char('Name', default='/', size=64, required=False,
  71. readonly=False)
  72. m2 = fields.Integer('M2')
  73. top_id = fields.Many2one(comodel_name='real.estate.top', string='Top',
  74. ondelete='cascade')
  75. class real_estate_top(models.Model):
  76. _name = 'real.estate.top'
  77. @api.multi
  78. def _get_mount_point(self):
  79. user = self.env.user
  80. company = user.company_id
  81. for top in self:
  82. if user.document_mount:
  83. mount = user.default_mount_agreement
  84. else:
  85. mount = company.default_mount_agreement
  86. if user.document_client:
  87. client = user.document_client
  88. else:
  89. client = company.default_document_client
  90. model_id = self.env['ir.model'].search([('model', '=',
  91. 'real.estate.top')])
  92. dir_obj = self.env['document.directory']
  93. dir_id = dir_obj.search([('ressource_type_id', '=', model_id.id),
  94. ('domain', '=', '[]')])
  95. path = ''
  96. if client == 'unix':
  97. path = mount + 'Real_Estate' + '/' + top.name + '/'
  98. elif client == 'win':
  99. path = mount + 'Real_Estate' + '\\' + top.name + '\\'
  100. top.attachments_url = path
  101. @api.depends('flat_usage_m2', 'ground_m2', 'office_m2', 'chalet_usage_m2',
  102. 'land_m2')
  103. def _m2_get(self):
  104. for top in self:
  105. if top.type in ['flat']:
  106. top.m2 = top.flat_usage_m2
  107. elif top.type in ['shop', 'industrial_unit', 'hotel_industry',
  108. 'premise']:
  109. top.m2 = top.ground_m2
  110. elif top.type in ['office', 'premise-office']:
  111. top.m2 = top.office_m2
  112. elif top.type in ['chalet', 'house']:
  113. top.m2 = top.chalet_usage_m2
  114. elif top.type in ['land']:
  115. top.m2 = top.land_m2
  116. else:
  117. top.m2 = 0
  118. @api.multi
  119. def _cons_m2_get(self):
  120. for top in self:
  121. if top.type in ['flat']:
  122. top.cons_m2 = top.flat_cons_m2
  123. elif top.type in ['shop', 'industrial_unit', 'hotel_industry',
  124. 'premise']:
  125. top.cons_m2 = top.ground_cons_m2
  126. elif top.type in ['office', 'premise-office']:
  127. top.cons_m2 = top.office_cons_m2
  128. elif top.type in ['chalet', 'house']:
  129. top.cons_m2 = top.chalet_cons_m2
  130. elif top.type in ['land']:
  131. top.cons_m2 = top.land_cons_m2
  132. else:
  133. top.cons_m2 = 0
  134. OPERATIONS = [('sale', 'Sale'),
  135. ('rent', 'Rent'),
  136. ('sale_rent', 'Sale & Rent'),
  137. ('rent_sale_option', 'Rent with sale option'),
  138. ('transfer', 'Transfer'),
  139. ('valuation', 'Valuation')]
  140. ENERGY_EFFICIENCY = [('in_process', 'In process'),
  141. ('exempt', 'Exempt'),
  142. ('yes', 'Yes'),
  143. ('a', 'A'),
  144. ('b', 'B'),
  145. ('c', 'C'),
  146. ('d', 'D'),
  147. ('e', 'E'),
  148. ('f', 'F'),
  149. ('g', 'G')]
  150. ORIENTATION = [('all', 'All'),
  151. ('north', 'North'),
  152. ('northeast', 'Northeast'),
  153. ('east', 'East'),
  154. ('southeast', 'South-Easth'),
  155. ('south', 'South'),
  156. ('southwest', 'South West'),
  157. ('west', 'West'),
  158. ('northwest', 'Northwest'),
  159. ('north-south', 'North-South'),
  160. ('east-west', 'East-West')]
  161. FURNISHED = [('yes', 'Yes'),
  162. ('half', 'Half'),
  163. ('no', 'No')]
  164. create_date = fields.Datetime('Create Date', readonly=True)
  165. write_date = fields.Datetime('Last Write Date', readonly=True)
  166. name = fields.Char('Reference', size=64, select=True, readonly=True)
  167. address = fields.Char('Address', required=True)
  168. user_id = fields.Many2one(
  169. comodel_name='res.users', string='Agent',
  170. default=lambda self: self.env.user)
  171. stair = fields.Char('Stair')
  172. number = fields.Char('Number', size=64, select=True)
  173. floor = fields.Char('Floor', size=64, select=True)
  174. type = fields.Selection(TYPES, 'Type', default='unlimited', required=True,
  175. select=True)
  176. zone = fields.Many2one('real.estate.zone', 'Zone', required=True,
  177. select=True)
  178. city_id = fields.Many2one(
  179. 'res.better.zip', 'Location', required=False,
  180. help='Usa el nombre o el C.P para buscar la localización')
  181. partner_id = fields.Many2one(
  182. 'res.partner', 'Owner', select=True,
  183. domain=[('real_estate_type', '=', 'owner')])
  184. operation = fields.Selection(OPERATIONS, 'Operation', default='sale',
  185. required=True, select=True)
  186. date = fields.Date('Date', required=True)
  187. updated_date = fields.Date('Updated Date')
  188. number_keys = fields.Char('Number of Keys')
  189. exclusive = fields.Boolean('Exclusive')
  190. exclusive_date = fields.Date('Exclusive Date')
  191. agreements = fields.One2many('rental.agreement', 'top_id',
  192. 'Rental Agreements')
  193. attachments_url = fields.Char(compute='_get_mount_point', store=False,
  194. size=1024, string='Attachments URL')
  195. # Common information
  196. sale_price = fields.Float('Sale Price')
  197. rent_price = fields.Float('Rent Price')
  198. homeowners_expenses = fields.Char('Homeowners Expenses')
  199. homeowners_expenses_included = fields.Boolean('Included')
  200. deposit = fields.Char('Deposit')
  201. note = fields.Text('Notes')
  202. available = fields.Boolean('Available', default=lambda *a: 1)
  203. subtype = fields.Many2one('real.estate.subtype', 'Subtype', select=True)
  204. energy_efficiency = fields.Selection(ENERGY_EFFICIENCY,
  205. 'Energy Efficiency',
  206. default='in_process', required=False)
  207. energy_date = fields.Date('Date Energy Efficiency')
  208. energy_emission = fields.Integer('Energy Emission')
  209. energy_number = fields.Integer('Energy Number')
  210. energy_doc = fields.Binary('Energy Certificate')
  211. doc_filename = fields.Char("Doc Filename")
  212. retribution = fields.Char('Retribution')
  213. buyer_id = fields.Many2one('res.partner', 'Buyer',
  214. domain=[('real_estate_type', '=', 'buyer')])
  215. m2 = fields.Float(compute='_m2_get', string='M2', store=True)
  216. cons_m2 = fields.Float(compute='_cons_m2_get', string='Constructed M2',
  217. store=False)
  218. subdivision_ids = fields.One2many(
  219. comodel_name='real.estate.top.subsivision', inverse_name='top_id',
  220. string='Subdivisions', required=False)
  221. # Flat, Chalet, Town House information
  222. kitchen = fields.Integer('Kitchen')
  223. kitchen_description = fields.Char('Kitchen Description')
  224. hall = fields.Integer('Hall')
  225. hall_description = fields.Char('Hall Description')
  226. rooms = fields.Integer('Rooms')
  227. room_description = fields.Char('Room Description')
  228. bathroom = fields.Integer('Bathroom')
  229. bath_description = fields.Char('Bathroom Description')
  230. toilet = fields.Integer('Toilet')
  231. toilet_description = fields.Char('Toilet Description')
  232. orientation = fields.Selection(ORIENTATION, 'Orientation')
  233. parking = fields.Integer('Parking')
  234. parking_description = fields.Char('Parking Description')
  235. box_room = fields.Integer('Box Room')
  236. box_room_description = fields.Char('Box Room Description')
  237. outside = fields.Boolean('Outside')
  238. balcony = fields.Char('Balcony')
  239. note_flat = fields.Text('Notes')
  240. # Rent Flat, Chalet or Town house
  241. bedrooms = fields.Integer('Bedrooms')
  242. built_in_closet = fields.Integer('Built-in Closet')
  243. furnished = fields.Selection(FURNISHED, 'Furnished')
  244. furnished_description = fields.Char('Furnished Description')
  245. # Suppliers
  246. administrator = fields.Char('Administrator')
  247. administrator_phone = fields.Char('Telephone')
  248. email = fields.Char('E-Mail')
  249. website = fields.Char('Website',
  250. help="Website of Administrator")
  251. light_ref = fields.Char('Light Reference')
  252. gas_ref = fields.Char('Gas Reference')
  253. aqua_ref = fields.Char('Aqua Reference')
  254. # Only Flat.
  255. flat_usage_m2 = fields.Float('Usage M2')
  256. flat_cons_m2 = fields.Float('Constructed M2')
  257. elevator = fields.Boolean('Elevator')
  258. flat_heating = fields.Many2one('real.estate.heating', 'Heating')
  259. flat_hotwater = fields.Many2one('real.estate.hotwater', 'Hot Water')
  260. students = fields.Boolean('Estudiantes')
  261. # Only Chalet, Town House
  262. chalet_usage_m2 = fields.Float('Usage M2')
  263. chalet_cons_m2 = fields.Float('Constructed M2')
  264. plot_m2 = fields.Float('Plot M2')
  265. chalet_basement = fields.Float('Basement')
  266. chalet_ground = fields.Float('Ground')
  267. first_floor = fields.Float('First Floor')
  268. second_floor = fields.Float('Second Floor')
  269. garden_m2 = fields.Float('Garden M2')
  270. swimming_pool = fields.Boolean('Swimming Pool')
  271. floor_number = fields.Integer('Floor Number')
  272. chalet_heating = fields.Many2one('real.estate.heating', 'Heating')
  273. chalet_hotwater = fields.Many2one('real.estate.hotwater', 'Hot Water')
  274. # Industrial Unit information
  275. ground_m2 = fields.Float('Ground M2')
  276. ground_cons_m2 = fields.Float('Constructed M2')
  277. mezzanine_m2 = fields.Float('Mezzanine M2')
  278. basement_m2 = fields.Float('Basement M2')
  279. open_field_m2 = fields.Float('Open Field M2')
  280. height = fields.Float('Height')
  281. electricity = fields.Boolean('Eletricity')
  282. triphase = fields.Boolean('Triphase')
  283. locker_room = fields.Integer('Locker Room')
  284. offices = fields.Integer('Offices')
  285. fire_fighting = fields.Char('Fire-Fighting')
  286. gantry_crane = fields.Char('Gantry Crane')
  287. shop_window = fields.Char('Shop Window')
  288. industrial_toilet = fields.Integer('Toilet')
  289. industrial_prepared = fields.Boolean('Prepared')
  290. # Office information
  291. office_m2 = fields.Float('Office M2')
  292. office_cons_m2 = fields.Float('Constructed Office M2')
  293. office_electricity = fields.Boolean('Eletricity')
  294. office_toilets = fields.Char('Toilets')
  295. office_toilet_description = fields.Char('Toilet Description')
  296. office_outside = fields.Boolean('Outside')
  297. office_elevator = fields.Boolean('Elevator')
  298. office_heating = fields.Many2one('real.estate.heating', 'Heating')
  299. office_air_conditioning = fields.Char('Air Conditioning')
  300. structural_barriers = fields.Boolean('Structural Barriers')
  301. office_parking = fields.Char('Parking')
  302. office_boxroom = fields.Char('Box Room')
  303. # Shop and Premise Information
  304. shop_electricity = fields.Boolean('Eletricity')
  305. shop_toilet = fields.Integer('Toilet')
  306. shop_facade = fields.Char('Facade')
  307. shop_heating = fields.Many2one('real.estate.heating', 'Heating')
  308. shop_air_conditioning = fields.Boolean('Air Conditioning')
  309. shop_prepared = fields.Boolean('Prepared')
  310. # Hotel industry
  311. fumes_vent = fields.Boolean('Fumes Vent')
  312. # Land
  313. land_m2 = fields.Float('Land M2')
  314. land_cons_m2 = fields.Float('Usage Land M2')
  315. land_type = fields.Many2one('real.estate.land.type', 'Land Type')
  316. land_state = fields.Many2one('real.estate.land.state', 'Land state')
  317. # meetings
  318. top_meetings = fields.Integer(compute='tops_meetings_count',
  319. string='Top Meetings', store=False)
  320. @api.model
  321. def create(self, vals):
  322. vals['name'] = self.env['ir.sequence'].get('real.estate.top')
  323. res = super(real_estate_top, self).create(vals)
  324. return res
  325. @api.multi
  326. def tops_meetings_count(self):
  327. for top in self:
  328. num_meetings = len(self.env['calendar.event'].search(
  329. [('top_id', '=', top.id)]))
  330. top.top_meetings = num_meetings