rental_agreement.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. class rental_agreement(models.Model):
  26. _name = 'rental.agreement'
  27. '''def _get_mount_point(self,cr,uid,ids,name,arg,context={}):
  28. res = {}
  29. user = self.pool.get('res.users').browse(cr, uid, uid)
  30. company = user.company_id
  31. for top in self.browse(cr,uid,ids,context):
  32. if user.document_mount:
  33. mount = user.default_mount_agreement
  34. else:
  35. mount = company.default_mount_agreement
  36. if user.document_client:
  37. client = user.document_client
  38. else:
  39. client = company.default_document_client
  40. model_obj = self.pool.get('ir.model')
  41. model_id = model_obj.search(cr,uid,[('model','=','rental.agreement')])[0]
  42. dir_obj = self.pool.get('document.directory')
  43. dir_id = dir_obj.search(cr,uid,[('ressource_type_id','=',model_id),('domain','=','[]')])[0]
  44. diry = dir_obj.browse(cr,uid,dir_id,context)
  45. path = ''
  46. if client == 'unix':
  47. path = mount + diry.name + '/' + top.name + '/'
  48. elif client == 'win':
  49. path = mount + diry.name + '\\' + top.name + '\\'
  50. elif client == 'web':
  51. data_pool = self.pool.get('ir.model.data')
  52. aid = data_pool._get_id(cr, uid, 'document_ftp', 'action_document_browse')
  53. aid = data_pool.browse(cr, uid, aid, context=context).res_id
  54. ftp_url = self.pool.get('ir.actions.url').browse(cr, uid, aid, context=context)
  55. url = ftp_url.url and ftp_url.url.split('ftp://') or []
  56. if url:
  57. url = url[1]
  58. if url[-1] == '/':
  59. url = url[:-1]
  60. else:
  61. url = '%s:%s' %(ftpserver.HOST, ftpserver.PORT)
  62. path = 'ftp://%s@%s'%(user.login, url) + '/' + diry.name + '/' + top.name + '/'
  63. res[top.id] = path
  64. return res
  65. '''
  66. @api.multi
  67. def _get_mount_point(self):
  68. user = self.env.user
  69. print user
  70. company = user.company_id
  71. print company
  72. for top in self:
  73. if user.document_mount:
  74. mount = user.default_mount_agreement
  75. print mount
  76. else:
  77. mount = company.default_mount_agreement
  78. print mount
  79. if user.document_client:
  80. client = user.document_client
  81. print client
  82. else:
  83. client = company.default_document_client
  84. print client
  85. model_id = self.env['ir.model'].search([('model','=',
  86. 'real.estate.top')])
  87. print model_id
  88. dir_obj = self.env['document.directory']
  89. dir_id = dir_obj.search([('ressource_type_id','=',model_id.id),
  90. ('domain','=','[]')])
  91. print dir_id.name
  92. print top.name
  93. path = ''
  94. if client == 'unix':
  95. path = mount + 'Real_Estate' + '/' + top.name + '/'
  96. elif client == 'win':
  97. path = mount + 'Real_Estate' + '\\' + top.name + '\\'
  98. top.rent_attachments_url = path
  99. name = fields.Char('Reference', size=64, select=True, readonly=True)
  100. partner_id = fields.Many2one('res.partner',
  101. 'Tenant',
  102. select=True,
  103. required=True,
  104. domain= [('real_estate_type','=','tenant')])
  105. signing_date = fields.Date('Signing date')
  106. start_date = fields.Date('Start date', required=True)
  107. end_date = fields.Date('End date', required=True)
  108. rent_price = fields.Float('Rent Price')
  109. notes = fields.Text('Notes')
  110. top_id = fields.Many2one('real.estate.top', 'Top', required=True,
  111. ondelete='cascade', select=True)
  112. owner_id = fields.Many2one('res.partner',
  113. 'Owner',
  114. select=True,
  115. domain= [('real_estate_type','=','owner')])
  116. rent_attachments_url = fields.Char(compute='_get_mount_point', store=False,
  117. string='Attachments URL')
  118. _order = 'start_date'
  119. @api.onchange('top_id')
  120. def onchange_top_id(self):
  121. if self.top_id:
  122. owner_id = self.top_id.partner_id
  123. @api.model
  124. def create(self, vals):
  125. vals['name'] = self.env['ir.sequence'].get('rental.agreement')
  126. res = super(rental_agreement, self).create(vals)
  127. return res