Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP]sale_commission_product_criteria_domain: convert constraint to python function #560

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sale_commission_product_criteria_domain/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
)
27 changes: 18 additions & 9 deletions sale_commission_product_criteria_domain/models/commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@
_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"
Expand Down Expand Up @@ -87,3 +78,21 @@
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(

Check warning on line 93 in sale_commission_product_criteria_domain/models/commission.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_product_criteria_domain/models/commission.py#L93

Added line #L93 was not covered by tests
_(
"You can only add one time each agent into Commission Items "
"Groups Restrictions table."
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -434,7 +435,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
Loading