Created
August 24, 2017 05:59
-
-
Save repodevs/f6015cdc8fca75bdc473167be7b06a67 to your computer and use it in GitHub Desktop.
an ugly method, to constrains odoo default_code (and name)
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# © 2017 Edi Santoso <[email protected]> | |
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) | |
from odoo import api, fields, models, _ | |
class Product(models.Model): | |
_inherit = 'product.template' | |
@api.constrains('default_code', 'name') | |
def _check_code(self): | |
if self.default_code or self.name: | |
exi = self.env['product.template'].search_count(['|',('name', '=', self.name),('default_code', '=', self.default_code)]) | |
if exi > 1: | |
raise ValueError(_("Code / Name already used !!!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment