res_repetidora.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import fields, osv
  22. def location_name_search(self, cr, user, name='', args=None, operator='ilike',
  23. context=None, limit=100):
  24. if not args:
  25. args = []
  26. ids = []
  27. if len(name) == 6:
  28. ids = self.search(cr, user, [('code', 'ilike', name)] + args,
  29. limit=limit, context=context)
  30. search_domain = [('name', operator, name)]
  31. if ids: search_domain.append(('id', 'not in', ids))
  32. ids.extend(self.search(cr, user, search_domain + args,
  33. limit=limit, context=context))
  34. locations = self.name_get(cr, user, ids, context)
  35. return sorted(locations, key=lambda (id, name): ids.index(id))
  36. class Repetidora(osv.osv):
  37. _name = 'res.repetidora'
  38. _description = 'Repetidora'
  39. _columns = {
  40. 'name': fields.char('Descripcion Repetidora',
  41. help='El nombre completo de Repetidora.', required=True),
  42. 'code': fields.char('Repetidora Codigo', size=6,
  43. help='El codigo de repetidora en cuatro caracter.\n'
  44. 'Puedes utilizar este campo para una busqueda rapida.'),
  45. 'address_format': fields.text('Formato Repetidora', help="""You can use the python-style string patern with all the field of the address \
  46. (for example, use '%(street)s' to display the field 'street') plus
  47. \n%(state_name)s: the name of the state
  48. \n%(state_code)s: the code of the state
  49. \n%(country_name)s: the name of the country
  50. \n%(country_code)s: the code of the country"""),
  51. 'repetidora_group_ids': fields.many2many('res.repetidora.group', 'res_repetidora_res_repetidora_group_rel', 'res_repetidora_id', 'res_repetidora_group_id', string='Grupo repetidora'),
  52. }
  53. _sql_constraints = [
  54. ('name_uniq', 'unique (name)',
  55. 'La descripcion de la repetidora debe ser unica !'),
  56. ('code_uniq', 'unique (code)',
  57. 'El codigo de la repetidora de la repetidora debe ser unica !')
  58. ]
  59. _defaults = {
  60. 'address_format': "%(city)s %(state_code)s \n%(country_name)s",
  61. }
  62. _order='name'
  63. name_search = location_name_search
  64. def create(self, cursor, user, vals, context=None):
  65. if vals.get('code'):
  66. vals['code'] = vals['code'].upper()
  67. return super(Repetidora, self).create(cursor, user, vals,
  68. context=context)
  69. def write(self, cursor, user, ids, vals, context=None):
  70. if vals.get('code'):
  71. vals['code'] = vals['code'].upper()
  72. return super(Repetidora, self).write(cursor, user, ids, vals,
  73. context=context)
  74. class RepetidoraGroup(osv.osv):
  75. _description="Grupo Repetidora"
  76. _name = 'res.repetidora.group'
  77. _columns = {
  78. 'name': fields.char('Name', required=True),
  79. 'repetidora_ids': fields.many2many('res.repetidora', 'res_repetidora_res_repetidora_group_rel', 'res_repetidora_group_id', 'res_repetidora_id', string='Repetidoras'),
  80. }
  81. class RepetidoraSectorial(osv.osv):
  82. _description="Sectorial"
  83. _name = 'res.repetidora.sectorial'
  84. _columns = {
  85. 'repetidora_id': fields.many2one('res.repetidora', 'Repetidora',
  86. required=True),
  87. 'name': fields.char('Nombre Sectorial', required=True,
  88. help='Descripcion Sectorial.'),
  89. 'code': fields.char('Codigo Sectorial', size=6,
  90. help='El codigo sectorial en max. cuatro caracteres.', required=True),
  91. }
  92. _order = 'code'
  93. name_search = location_name_search
  94. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: