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