From 03d06865dea71a72a1647159ca22d0a82ed5302e Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 21 Dec 2021 15:32:30 +0100 Subject: [PATCH] [FIX] sale_purchase: Fix wrong constraint definition constraint validation should work correctly on multi records creation/updates --- addons/sale_purchase/models/product_template.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/sale_purchase/models/product_template.py b/addons/sale_purchase/models/product_template.py index 70e926e084e..a5d1b22feda 100644 --- a/addons/sale_purchase/models/product_template.py +++ b/addons/sale_purchase/models/product_template.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models +from odoo import api, fields, models, _ from odoo.exceptions import ValidationError @@ -18,9 +18,11 @@ class ProductTemplate(models.Model): ] @api.constrains('service_to_purchase', 'seller_ids') - def validate_service_to_purchase(self): - if self.service_to_purchase and not self.seller_ids: - raise ValidationError("Please define the vendor from whom you would like to purchase this service automatically.") + def _check_service_to_purchase(self): + for template in self: + if template.service_to_purchase and not template.seller_ids: + raise ValidationError(_( + "Please define the vendor from whom you would like to purchase this service automatically.")) @api.depends('type', 'expense_policy') def _compute_service_to_purchase(self):