From 6e86df9cc5223ffcb2c71aaddbdda7da3ad0a488 Mon Sep 17 00:00:00 2001 From: PicchiSeba Date: Fri, 30 Aug 2024 12:10:54 +0200 Subject: [PATCH] [IMP]sale_commission_product_criteria_domain: convert constraint to python function --- .../__manifest__.py | 2 +- .../migrations/14.0.1.0.12/pre-migration.py | 11 ++++++++ .../models/commission.py | 27 ++++++++++++------- .../static/description/index.html | 11 +++++--- 4 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 sale_commission_product_criteria_domain/migrations/14.0.1.0.12/pre-migration.py diff --git a/sale_commission_product_criteria_domain/__manifest__.py b/sale_commission_product_criteria_domain/__manifest__.py index 8b44a235f..e7c797e78 100644 --- a/sale_commission_product_criteria_domain/__manifest__.py +++ b/sale_commission_product_criteria_domain/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html { "name": "Sale Commission Product Criteria Domain", - "version": "14.0.1.0.11", + "version": "14.0.1.0.12", "author": "Ilyas," "Ooops404," "Odoo Community Association (OCA)", "contributors": ["Ilyas"], "maintainers": ["ilyasProgrammer", "aleuffre", "renda-dev", "PicchiSeba"], diff --git a/sale_commission_product_criteria_domain/migrations/14.0.1.0.12/pre-migration.py b/sale_commission_product_criteria_domain/migrations/14.0.1.0.12/pre-migration.py new file mode 100644 index 000000000..b51c52fdc --- /dev/null +++ b/sale_commission_product_criteria_domain/migrations/14.0.1.0.12/pre-migration.py @@ -0,0 +1,11 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.delete_sql_constraint_safely( + env, + "sale_commission_product_criteria_domain", + "commission_item_agent", + "commission_item_unique_agent", + ) diff --git a/sale_commission_product_criteria_domain/models/commission.py b/sale_commission_product_criteria_domain/models/commission.py index 9062344ab..ec5094baf 100644 --- a/sale_commission_product_criteria_domain/models/commission.py +++ b/sale_commission_product_criteria_domain/models/commission.py @@ -42,15 +42,6 @@ class CommissionItemAgent(models.Model): _name = "commission.item.agent" _description = "Commission Item Agent" - _sql_constraints = [ - ( - "commission_item_unique_agent", - "UNIQUE(partner_id, agent_id)", - "You can only add one time each agent into Commission " - "Items Groups Restrictions table.", - ) - ] - partner_agent_ids = fields.Many2many(related="partner_id.agent_ids") agent_group_ids = fields.Many2many( "commission.items.group", compute="_compute_agent_group_ids" @@ -87,3 +78,21 @@ def _constraint_commission_item_agent_ids(self): raise exceptions.ValidationError( _("At least one group for each restriction must be selected.") ) + + @api.constrains("agent_id", "partner_id") + def _constraint_unique_commission_item_agent_ids(self): + for cia in self: + duplicate_items = self.search( + [ + ("id", "!=", cia.id), + ("partner_id", "=", cia.partner_id.id), + ("agent_id", "=", cia.agent_id.id), + ] + ) + if duplicate_items: + raise exceptions.ValidationError( + _( + "You can only add one time each agent into Commission Items " + "Groups Restrictions table." + ) + ) diff --git a/sale_commission_product_criteria_domain/static/description/index.html b/sale_commission_product_criteria_domain/static/description/index.html index d00cae3df..4b0b8f831 100644 --- a/sale_commission_product_criteria_domain/static/description/index.html +++ b/sale_commission_product_criteria_domain/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -434,7 +435,9 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.