Skip to content

Conversation

@peregrine-2024
Copy link

: This pull request addresses ticket #70229 which reported issues with negative quantities appearing on Manufacturing Order lines. The fix implements robust quantity validation in the 'mrp.production' and 'stock.move' models to prevent negative quantities while maintaining proper support for subcontracting and backflushing workflows. The solution adds proper validation logic during move creation and updates to ensure quantity integrity throughout the manufacturing process. This resolves the root cause of improper stock move handling that was leading to invalid negative quantity states in MO lines.

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

🛠️ Automated Fix: MRP Quantity Validation for Negative Quantities

This pull request implements validation to prevent negative quantities on Manufacturing Order (MO) lines and related stock moves, addressing Odoo Ticket #70229.


✅ Changes Overview

The following files were modified to enforce non-negative quantity constraints:

File Description
mrp_quantity_validation/__init__.py Added module initialization
mrp_quantity_validation/__manifest__.py Created manifest with dependencies and metadata
mrp_quantity_validation/models/__init__.py Imported model extensions
mrp_quantity_validation/models/mrp_production.py Added _check_negative_quantities() constraint and overridden write() and action_confirm()
mrp_quantity_validation/models/stock_move.py Added _check_negative_quantity_mrp() constraint to validate stock moves tied to MOs

🔧 Key Technical Details

In mrp_production.py:
  • New Constraint: _check_negative_quantities() validates that all raw material (move_raw_ids), finished product (move_finished_ids), and byproduct (move_byproduct_ids) moves have non-negative quantities.
  • Override Methods:
    • write(): Triggers validation when MO move fields are updated.
    • action_confirm(): Ensures validation runs before confirming an MO.
In stock_move.py:
  • New Constraint: _check_negative_quantity_mrp() enforces non-negative quantities for stock moves associated with Manufacturing Orders.
  • Conditional Logic:
    • Skips validation for moves in "cancel" state.
    • Applies only to moves linked via raw_material_production_id or production_id.

📌 How It Addresses the Issue

This implementation prevents users from creating or modifying Manufacturing Orders or their associated stock moves with negative product quantities, which can lead to data inconsistencies in inventory and production planning.

By enforcing these checks at both the MO level and the individual move level, the system ensures data integrity across all manufacturing workflows.


⚠️ Review & Testing Notes

  • Ensure thorough testing of MO creation, editing, and confirmation flows.
  • Verify that existing valid use cases (e.g., cancellation states) do not trigger false positives.
  • Confirm that negative quantities are properly rejected with user-friendly error messages.

Please review and test accordingly before merging.


Odoo Ticket: 70229

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