diff --git a/models/__init__.py b/models/__init__.py index c6cc3b329891fd73ef05a76005f6d232d28c17d9..0d85126b7381eec91049677e2c0f0715a1a42f43 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import res_partner +from . import res_partner_product_family diff --git a/models/res_partner.py b/models/res_partner.py index 13a29ddf8c498961bf779b444871f775c0237654..58c8319407f592a914dc942f52fa621771eb694a 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -59,35 +59,6 @@ class ResPartner(models.Model): on_delete='restrict') -class ResPartnerProductFamily(models.Model): - _name = "res.partner.product.family" - _description = "Famille / Catégorie Produit" - _parent_name = "parent_id" - _parent_store = True - _rec_name = 'name' - _order = 'parent_path, name' - - name = fields.Char('Catégorie / Famille produit', - index=True, required=True) - color = fields.Integer(string='Couleur') - parent_id = fields.Many2one( - comodel_name='res.partner.product.family', - string='Catégorie produit (parent)', - index=True, - ondelete='cascade') - parent_path = fields.Char(index=True) - child_ids = fields.One2many( - comodel_name='res.partner.product.family', - inverse_name='parent_id', - string='Famille produit') - - @api.constrains('parent_id') - def _check_origin_recursion(self): - if not self._check_recursion(): - raise ValidationError( - 'Vous ne pouvez pas créer des familles récursives.') - - class ResPartnerSector(models.Model): _name = "res.partner.sector" _description = "Secteur" diff --git a/models/res_partner_product_family.py b/models/res_partner_product_family.py new file mode 100644 index 0000000000000000000000000000000000000000..82ba79a9107ba3ed58e8c467bc60e89971974a2a --- /dev/null +++ b/models/res_partner_product_family.py @@ -0,0 +1,33 @@ +# Copyright 2020 Le Filament (<https://le-filament.com>) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartnerProductFamily(models.Model): + _name = "res.partner.product.family" + _description = "Famille / Catégorie Produit" + _parent_name = "parent_id" + _parent_store = True + _rec_name = 'name' + _order = 'parent_path, name' + + name = fields.Char('Catégorie / Famille produit', + index=True, required=True) + color = fields.Integer(string='Couleur') + parent_id = fields.Many2one( + comodel_name='res.partner.product.family', + string='Catégorie produit (parent)', + index=True, + ondelete='cascade') + parent_path = fields.Char(index=True) + child_ids = fields.One2many( + comodel_name='res.partner.product.family', + inverse_name='parent_id', + string='Famille produit') + + @api.constrains('parent_id') + def _check_origin_recursion(self): + if not self._check_recursion(): + raise ValidationError( + 'Vous ne pouvez pas créer des familles récursives.')