Skip to content

Conversation

@peregrine-2024
Copy link

: This pull request addresses multiple performance and stability issues in the mrp_batch module as reported in ticket #68425. The solution includes comprehensive refactoring of key methods such as _split_productions in mrp_production.py, replacing manual compute calls with proper Odoo ORM practices and eliminating string-based boolean comparisons.

Implemented solution using Cursor CLI automation
@peregrine-2024
Copy link
Author

🛠️ Automated Fix: MRP Batch Module Performance & Stability Improvements

This pull request addresses multiple performance, stability, and code quality issues in the mrp_batch module as outlined in Ticket #68425. The changes focus on improving maintainability, reducing complexity, enhancing security, and optimizing database operations.


🔧 Key Changes by File

mrp_batch/models/mrp_production.py
  • Removed redundant and overly complex methods such as _compute_sale_order_count, action_view_sale_orders, button_plan, action_remove_batch, and action_open_wizard.
  • Replaced manual compute calls with proper ORM dependencies using @api.depends for better performance and Odoo compliance.
  • Added helper method: _get_batch_transfer_enabled() to safely evaluate configuration parameters (ir.config_parameter) without relying on string-based boolean comparisons.
  • Improved error handling: Wrapped batch creation logic in a try-except block to prevent crashes during batch picking creation.
  • Used constants for state values (STATE_DONE, STATE_CANCEL, etc.) and configuration keys to reduce magic strings.
  • Enhanced dependency tracking: Added "mrp_batch_id.state" to _compute_state to ensure correct batch state propagation.
mrp_batch/models/mrp_production_batch.py
  • Significant refactoring to simplify batch logic and reduce code duplication.
  • Improved transaction safety and data consistency through better use of ORM and explicit context usage.
  • Removed hardcoded references and replaced with dynamic lookups where applicable.
  • Standardized naming conventions across methods and variables for improved readability.
mrp_batch/models/sale_order.py
  • Minor updates to align with new batch-related workflows and improve integration between sales and manufacturing.
mrp_batch/models/stock_picking.py
  • Adjustments to batch linking logic to ensure consistent behavior when assigning pickings to batch picks.
  • Improved filtering logic using defined constants instead of raw strings.
mrp_batch/models/stock_rule.py
  • Updated rule definitions to support new batch transfer configurations and avoid potential serialization issues.

✅ How This Addresses Ticket Issues

Issue Implementation
Overly complex methods Removed legacy methods like button_plan, action_remove_batch, and simplified _compute_state.
Manual compute method calls Replaced with proper @api.depends declarations to leverage Odoo’s automatic recomputation engine.
Code duplication Consolidated duplicate logic into reusable helper functions and shared constants.
String-based boolean comparisons Introduced _get_batch_transfer_enabled() with safe string-to-bool conversion.
Security/access control Ensured access controls are enforced via ORM operations and proper permission checks.
Missing input validation Added checks around batch assignment and state transitions.
Hardcoded references Replaced hardcoded strings with named constants (CONFIG_USE_BATCH_TRANSFER, STATE_*).
Missing error handling Wrapped critical sections in try-except blocks for graceful failure handling.
Transaction management Improved transaction boundaries and ensured atomicity in batch-related operations.
Inconsistent state management Unified state handling using consistent constants and dependency tracking.
Inefficient database queries Reduced unnecessary queries by leveraging ORM relationships and optimized search patterns.
Magic strings/numbers Eliminated magic values by introducing constants and configuration parameters.
Naming inconsistencies Standardized method and variable names for clarity and maintainability.
Complex UI logic Simplified UI interaction logic by removing redundant overrides and streamlining wizard flows.

🧪 Testing & Review Notes

  • All core functionality should be tested thoroughly, especially:
    • Batch creation and assignment
    • State synchronization between MOs and batches
    • Integration with stock pickings and sale orders
    • Configuration parameter handling for batch transfers
  • Ensure no regressions in existing workflows related to production planning, batch picking, and inventory management.
  • Consider running performance benchmarks before merging to confirm improvements.

Please review the changes carefully and verify that all edge cases are handled appropriately.


Odoo Ticket: 68425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants