partner.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. import platform
  26. class res_partner(models.Model):
  27. _inherit = "res.partner"
  28. '''
  29. def _get_mount_point(self,cr,uid,ids,name,arg,context={}):
  30. res = {}
  31. user = self.pool.get('res.users').browse(cr, uid, uid)
  32. company = user.company_id
  33. for partner in self.browse(cr,uid,ids,context):
  34. if user.document_mount:
  35. mount = user.default_mount_agreement
  36. else:
  37. mount = company.default_mount_agreement
  38. if user.document_client:
  39. client = user.document_client
  40. else:
  41. client = company.default_document_client
  42. model_obj = self.pool.get('ir.model')
  43. model_id = model_obj.search(cr,uid,[('model','=','res.partner')])[0]
  44. dir_obj = self.pool.get('document.directory')
  45. dir_id = dir_obj.search(cr,uid,[('ressource_type_id','=',model_id)])[0]
  46. diry = dir_obj.browse(cr,uid,dir_id,context)
  47. path = ''
  48. if client == 'unix':
  49. path = mount + diry.name + '/' + partner.ref + '/'
  50. elif client == 'win':
  51. path = mount + diry.name + '\\' + partner.ref + '\\'
  52. elif client == 'web':
  53. data_pool = self.pool.get('ir.model.data')
  54. aid = data_pool._get_id(cr, uid, 'document_ftp', 'action_document_browse')
  55. aid = data_pool.browse(cr, uid, aid, context=context).res_id
  56. ftp_url = self.pool.get('ir.actions.url').browse(cr, uid, aid, context=context)
  57. url = ftp_url.url and ftp_url.url.split('ftp://') or []
  58. if url:
  59. url = url[1]
  60. if url[-1] == '/':
  61. url = url[:-1]
  62. else:
  63. url = '%s:%s' %(ftpserver.HOST, ftpserver.PORT)
  64. path = 'ftp://%s@%s'%(user.login, url) + '/' + diry.name + '/' + partner.ref + '/'
  65. res[partner.id] = path
  66. return res
  67. '''
  68. #prueba
  69. @api.multi
  70. def _get_mount_point(self):
  71. user = self.env.user
  72. company = user.company_id
  73. for partner in self:
  74. if user.document_mount:
  75. mount = user.default_mount_agreement
  76. else:
  77. mount = company.default_mount_agreement
  78. if user.document_client:
  79. client = user.document_client
  80. else:
  81. client = company.default_document_client
  82. model_id = self.env['ir.model'].search([('model','=',
  83. 'res.partner')])
  84. dir_obj = self.env['document.directory']
  85. dir_id = dir_obj.search([('ressource_type_id','=',model_id.id)])
  86. path = ''
  87. if partner.ref:
  88. if client == 'unix':
  89. path = mount + dir_id.name + '/' + partner.ref + '/'
  90. elif client == 'win':
  91. path = mount + dir_id.name + '\\' + partner.ref + '\\'
  92. partner.partner_attachments_url = path
  93. name2 = fields.Char('Second Owner', size=128, required=False,
  94. select=True)
  95. vat2 = fields.Char('Second VAT',size=32 )
  96. real_estate_type = fields.Selection([('owner','Owner'),
  97. ('tenant','Tenant'),
  98. ('buyer','Buyer'),
  99. ('manage','Manage')], 'Type', required=True,
  100. select=True)
  101. partner_attachments_url = fields.Char(compute='_get_mount_point',
  102. store=False, size=1024,
  103. string='Attachments URL')