product_brand.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- encoding: utf-8 -*-
  2. ###############################################################################
  3. # #
  4. # product_brand for Odoo #
  5. # Copyright (C) 2009 NetAndCo (<http://www.netandco.net>). #
  6. # Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com> #
  7. # Copyright (C) 2014 prisnet.ch Seraphine Lantible <s.lantible@gmail.com> #
  8. # Copyright (C) 2015 Leonardo Donelli #
  9. # Contributors #
  10. # Mathieu Lemercier, mathieu@netandco.net #
  11. # Franck Bret, franck@netandco.net #
  12. # Seraphine Lantible, s.lantible@gmail.com, http://www.prisnet.ch #
  13. # Leonardo Donelli, donelli@webmonks.it, http://www.wearemonk.com #
  14. # #
  15. # This program is free software: you can redistribute it and/or modify #
  16. # it under the terms of the GNU Affero General Public License as #
  17. # published by the Free Software Foundation, either version 3 of the #
  18. # License, or (at your option) any later version. #
  19. # #
  20. # This program is distributed in the hope that it will be useful, #
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  23. # GNU Affero General Public License for more details. #
  24. # #
  25. # You should have received a copy of the GNU Affero General Public License #
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  27. # #
  28. ###############################################################################
  29. ###############################################################################
  30. # Product Brand is an Openobject module wich enable Brand management for #
  31. # products #
  32. ###############################################################################
  33. from openerp import models, fields, api
  34. class ProductBrand(models.Model):
  35. _name = 'product.brand'
  36. name = fields.Char('Brand Name', required=True)
  37. description = fields.Text('Description', translate=True)
  38. partner_id = fields.Many2one(
  39. 'res.partner',
  40. string='Partner',
  41. help='Select a partner for this brand if it exists',
  42. ondelete='restrict'
  43. )
  44. logo = fields.Binary('Logo File')
  45. product_ids = fields.One2many(
  46. 'product.template',
  47. 'product_brand_id',
  48. string='Brand Products',
  49. )
  50. products_count = fields.Integer(
  51. string='Number of products',
  52. compute='_get_products_count',
  53. )
  54. @api.one
  55. @api.depends('product_ids')
  56. def _get_products_count(self):
  57. self.products_count = len(self.product_ids)
  58. class ProductTemplate(models.Model):
  59. _inherit = 'product.template'
  60. product_brand_id = fields.Many2one(
  61. 'product.brand',
  62. string='Brand',
  63. help='Select a brand for this product'
  64. )