codigo_barra.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 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 import models, fields, api
  22. class product_template(models.Model):
  23. _name = 'product.template'
  24. _inherit = 'product.template'
  25. factory_reference = fields.Char('Referencia de fábrica',size=64)
  26. @api.multi
  27. def write(self, vals):
  28. prod_tmpl_id = super(product_template,self).write(vals)
  29. for p in self.product_variant_ids:
  30. prod = self.env['product.product'].browse(p['id'])
  31. ref = ''
  32. if prod.factory_reference:
  33. if prod['factory_reference'] != None:
  34. #prod.factory_reference = prod['factory_reference']
  35. prod.factory_reference = self.factory_reference
  36. ref = prod['factory_reference']
  37. elif self.factory_reference:
  38. prod.factory_reference = self.factory_reference
  39. ref = self['factory_reference']
  40. prod['default_code'] = ref
  41. return prod_tmpl_id
  42. class product_product(models.Model):
  43. _name = 'product.product'
  44. _inherit = 'product.product'
  45. factory_reference = fields.Char('Referencia de fábrica',size=64)
  46. @api.model
  47. def create(self, vals):
  48. prod_id = super(product_product,self).create(vals)
  49. self.copiar_referencia(prod_id)
  50. return prod_id
  51. @api.model
  52. def copiar_referencia(self,prod_id):
  53. # print prod_id['id']
  54. prod_tmpl = self.env['product.template'].browse(prod_id['product_tmpl_id']['id'])
  55. #print prod_tmpl
  56. ref = ''
  57. if prod_tmpl.factory_reference:
  58. prod_id['factory_reference'] = prod_tmpl.factory_reference
  59. ref = prod_tmpl.factory_reference
  60. prod_id['default_code'] = ref
  61. return True
  62. product_product()