You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.4 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Savoir-faire Linux
  6. # (<http://www.savoirfairelinux.com>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. import time
  23. from openerp.osv import orm, fields
  24. class res_partner(orm.Model):
  25. """
  26. Inherits partner and adds function_ids : List of functions
  27. """
  28. _inherit = 'res.partner'
  29. def onchange_partner_function(self, cr, uid, ids, part, context=None):
  30. partner_pool = self.pool['res.partner']
  31. if not part:
  32. return {'value': None}
  33. partner_ids = partner_pool.search(cr, uid, [('id', '=', part)])
  34. function_ids = partner_pool.browse(
  35. cr, uid, partner_ids, context=context)[0].function_ids
  36. result = []
  37. if function_ids:
  38. for line in function_ids:
  39. result.append(line.id)
  40. dom = {'function_id': [('id', 'in', result)]}
  41. return {'domain': dom}
  42. def _get_history_lines(self, cr, uid, ids, name, arg, context=None):
  43. res = {}
  44. res_partner_pool = self.pool.get('res.partner')
  45. for record in self.browse(cr, uid, ids, context=context):
  46. if record.is_company:
  47. return res
  48. contact_ids = res_partner_pool.search(
  49. cr, uid, [
  50. ('contact_id', '=', record.id),
  51. ('active', '=', False),
  52. ], context=context
  53. )
  54. res[record.id] = [
  55. x.id for x in res_partner_pool.browse(cr, uid, contact_ids)
  56. if x.end_date and x.end_date <= time.strftime('%Y-%m-%d')
  57. ]
  58. return res
  59. _columns = {
  60. 'function_ids': fields.many2many(
  61. 'res.partner.function',
  62. 'function_partner_rel',
  63. 'partner_id',
  64. 'function_id',
  65. 'Functions',
  66. ),
  67. 'start_date': fields.date('Start date'),
  68. 'end_date': fields.date('End date'),
  69. 'naming': fields.char(
  70. 'Naming',
  71. help="Naming.",
  72. ),
  73. 'function_id': fields.many2one(
  74. 'res.partner.function',
  75. 'Position Occupied',
  76. ),
  77. 'other_contact_history_ids': fields.function(
  78. _get_history_lines,
  79. relation="res.partner",
  80. method=True,
  81. type="one2many",
  82. ),
  83. # Replace company by Organisation
  84. 'use_parent_address': fields.boolean(
  85. 'Use Organisation Address',
  86. help="Select this if you want to set organisation's address "
  87. "information for this contact",
  88. ),
  89. }