Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
# Copyright 2019 Onestein - Andrea Stirpe | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, fields | ||
from odoo import models, fields, api, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class MembershipCategory(models.Model): | ||
_name = "membership.membership_category" | ||
_description = "Membership category" | ||
|
||
name = fields.Char(required=True, translate=True) | ||
company_id = fields.Many2one('res.company') | ||
|
||
@api.constrains("company_id") | ||
def _check_company_id(self): | ||
if self.env.context.get("bypass_company_validation"): | ||
return | ||
categories = self.filtered(lambda c: c.company_id) | ||
templates = self.env['product.template'].search([ | ||
('membership_category_id', 'in', categories.ids), | ||
]).filtered( | ||
lambda t: t.company_id != t.membership_category_id.company_id) | ||
if templates: | ||
raise ValidationError(_( | ||
"You cannot change the Company, as this " | ||
"Membership Category is used by Product Template (%s)." | ||
) % fields.first(templates).name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters