summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2025-12-31 21:54:08 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2025-12-31 21:54:08 +0700
commit604598292fa99546b34422613a8f6399e1a55c61 (patch)
tree45bf5950b6ebf8690ad612c383ff8638c28ca52b
parent5374f1741bc3c3718a89884d9c5b7f36aa1d1e25 (diff)
<Miqdad> fix check duplicate
-rw-r--r--indoteknik_custom/models/keywords.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/indoteknik_custom/models/keywords.py b/indoteknik_custom/models/keywords.py
index d7cfc810..f6c1cf6e 100644
--- a/indoteknik_custom/models/keywords.py
+++ b/indoteknik_custom/models/keywords.py
@@ -66,15 +66,18 @@ class Keywords(models.Model):
if not record.name:
record.name = record.keywords
- # def check_already_exist(self):
- # model = self.env['keywords']
- # for record in self:
- # match = model.search([
- # ('keywords', '=', record.keywords),
- # ('category_id.id', '=', record.category_id.id)
- # ])
- # if match:
- # raise UserError("Tidak bisa create karena keywords sudah dipakai")
+ @api.constrains('keywords', 'category_id')
+ def check_already_exist(self):
+ for record in self:
+ if not (record.keywords and record.category_id):
+ continue
+ match = self.search([
+ ('id', '!=', record.id),
+ ('keywords', '=', record.keywords),
+ ('category_id', '=', record.category_id.id)
+ ], limit = 1)
+ if match:
+ raise UserError("Tidak bisa create karena keywords sudah dipakai")
def copy(self):
raise UserError("Duplicate Record not allowed")