product_genre.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- encoding: utf-8 -*-
  2. #################################################################################
  3. # #
  4. # product_genre for OpenERP #
  5. # Author: Victor Obrist #
  6. # contact: victor@paraguayenlaweb.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. from openerp.osv import orm, fields
  23. class product_genre(orm.Model):
  24. _name = 'product.genre'
  25. _columns = {
  26. 'name': fields.char('Genre Name'),
  27. # 'code': fields.integer('Genre Code', size=1, translate=True, required=True, help='Code for barcode generator'),
  28. 'reference': fields.char('Reference', size=1, translate=True, required=True, help='Reference for the product internal reference.'\
  29. 'One character lenght.'\
  30. 'E.g.: for Male could be M'),
  31. }
  32. def onchange_case(self, cr, uid, ids, reference):
  33. result = {'value': {
  34. 'reference': str(reference).upper()
  35. }
  36. }
  37. return result
  38. _sql_constraints = [
  39. ('reference_genre_uniq', 'unique (reference)', 'La referencia del género debe ser única!')
  40. ]
  41. class product_template(orm.Model):
  42. _inherit = 'product.template'
  43. _columns = {
  44. 'product_genre_id': fields.many2one(
  45. 'product.genre',
  46. 'Genero',
  47. help='Select a genre for this product.',
  48. ondelete='restrict',
  49. required=True)
  50. }