[IMP] *: improve python constraints performance
* Do not load x records from database when one is enough. Earlier SQL returns when a matching record is found. * any() can receive a generator as argument Do not explicitly cast a generator as list when it is not needed. Task Id: 2328664 COM PR: https://github.com/odoo/odoo/pull/55525 ENT PR: https://github.com/odoo/enterprise/pull/12250
This commit is contained in:
@@ -322,7 +322,7 @@ class PosConfig(models.Model):
|
||||
|
||||
@api.constrains('cash_control')
|
||||
def _check_session_state(self):
|
||||
open_session = self.env['pos.session'].search([('config_id', '=', self.id), ('state', '!=', 'closed')])
|
||||
open_session = self.env['pos.session'].search([('config_id', 'in', self.ids), ('state', '!=', 'closed')], limit=1)
|
||||
if open_session:
|
||||
raise ValidationError(_("You are not allowed to change the cash control status while a session is already opened."))
|
||||
|
||||
|
||||
@@ -928,7 +928,7 @@ class AccountCashRounding(models.Model):
|
||||
|
||||
@api.constrains('rounding', 'rounding_method', 'strategy')
|
||||
def _check_session_state(self):
|
||||
open_session = self.env['pos.session'].search([('config_id.rounding_method', '=', self.id), ('state', '!=', 'closed')])
|
||||
open_session = self.env['pos.session'].search([('config_id.rounding_method', 'in', self.ids), ('state', '!=', 'closed')], limit=1)
|
||||
if open_session:
|
||||
raise ValidationError(
|
||||
_("You are not allowed to change the cash rounding configuration while a pos session using it is already opened."))
|
||||
|
||||
@@ -107,7 +107,7 @@ class StockMoveLine(models.Model):
|
||||
|
||||
@api.constrains('qty_done')
|
||||
def _check_positive_qty_done(self):
|
||||
if any([ml.qty_done < 0 for ml in self]):
|
||||
if any(ml.qty_done < 0 for ml in self):
|
||||
raise ValidationError(_('You can not enter negative quantities.'))
|
||||
|
||||
@api.onchange('product_id', 'product_uom_id')
|
||||
|
||||
Reference in New Issue
Block a user