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