[ADD] [16.0] sale_commission_product_criteria_price_compliance#654
[ADD] [16.0] sale_commission_product_criteria_price_compliance#654
Conversation
e1776d9 to
c51d4dd
Compare
c51d4dd to
1b2607b
Compare
1b2607b to
bc736ea
Compare
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failure occurs because the module sale_commission_product_criteria_price_compliance depends on sale_price_compliance, which is not available in the test environment, causing a Failed to load registry error during module installation.
2. Suggested Fix
In sale_commission_product_criteria_price_compliance/__manifest__.py, add sale_price_compliance to the depends list only if it's actually required and available. Alternatively, if it's an optional dependency, consider using optional_dependencies or conditional loading logic in tests.
However, since this is a new module that explicitly extends sale_price_compliance, it must be included in depends. The root issue is likely that the test database setup does not include sale_price_compliance.
File: sale_commission_product_criteria_price_compliance/__manifest__.py
Lines: 20–21
Suggested Change: Ensure sale_price_compliance is installed in test environment or use optional_dependencies if not strictly required.
3. Additional Code Issues
a. Missing price_compliance_tier field definition in commission_item.py
The field price_compliance_tier in commission_item.py is defined as readonly=False, but no selection is provided. It inherits from product.price.compliance.threshold.tier.mixin, which should provide the selection, but this needs to be verified.
File: sale_commission_product_criteria_price_compliance/models/commission_item.py
Line: 12
Issue: No explicit selection is passed to fields.Selection(). If the mixin doesn't provide one, this will cause an error.
b. Potential ZeroDivisionError in _compute_price_compliance_tier
In commission_settlement_line.py, line 24:
settlement_line.price_compliance_tier = sale_line.price_compliance_tierIf sale_line is None (e.g., no sale line found), this will raise an AttributeError. While there's a check if sale_line, it's not robust enough.
File: sale_commission_product_criteria_price_compliance/models/commission_settlement_line.py
Line: 24
Suggested Fix: Add explicit None check or default fallback.
c. Use of f"""...""" with super() in SQL queries
In sale_commission_line_mixin.py, line 23:
res = f"""{res} AND (
item.price_compliance_tier IS NULL
OR item.price_compliance_tier = %(price_compliance_tier)s
)" "" # noqa: E202This is a raw SQL injection risk if res is not properly sanitized. Also, the """ usage is unnecessarily complex.
File: sale_commission_product_criteria_price_compliance/models/sale_commission_line_mixin.py
Line: 23
Suggested Fix: Use sql.SQL() and sql.Placeholder() for safer SQL composition or at least refactor to avoid raw string interpolation.
4. Test Improvements
a. Add TransactionCase for Commission Rules with Price Compliance
Create a test case that:
- Creates a commission type with product criteria
- Adds a rule with price compliance tier
- Creates a sale order line with a
price_compliance_tier - Verifies that the settlement line correctly reflects the tier
Test Pattern: TransactionCase
Module: sale_commission_product_criteria_price_compliance.tests.test_commission_item
b. Test sale_commission_line_mixin logic
Add a test that verifies:
_commission_items_query_paramscorrectly extractsprice_compliance_tier_commission_items_wherecorrectly filters onprice_compliance_tier_commission_items_ordercorrectly orders byprice_compliance_tier
Test Pattern: SavepointCase
Module: sale_commission_product_criteria_price_compliance.tests.test_mixin
c. Test Report Template Rendering
Ensure that the report template correctly renders the price_compliance_tier in the settlement document.
Test Pattern: TransactionCase
Module: sale_commission_product_criteria_price_compliance.tests.test_report
These tests should be tagged with @tag('post_install') or @tag('functional') to ensure they run after installation and validate behavior.
⏰ This PR has been open for 52 days.
Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)
Reciprocal Review Request
Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):
My open PRs across OCA:
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
Reviewing each other's work helps the whole community move forward. Thank you!
Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b
Allow to use Price Compliance Thresholds in Commisions.
https://www.loom.com/share/c442dbc2f4434abb88cd3f80bd97bb5d
PR Series
MT-12373 MT-13323 @moduon @rafaelbn @fcvalgar @Gelojr @yajo please review if you want 😄