diff --git a/README.md b/README.md index 64e13eb..72ce87d 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This Odoo module customizes the behavior of Manufacturing Orders (MO) regarding 1. **Lock Consumed Quantity**: - Prevents the automatic update of a component's "Consumed" quantity when the MO's "Quantity to Produce" is changed, **IF**: - The component already has a manually entered "Consumed" quantity (greater than 0). + - The component is marked as **Picked** (manual consumption) or has **Manual Consumption** flag set. - If a component has 0 consumed quantity and is not picked, it will continue to scale automatically based on the BOM ratio (standard behavior). diff --git a/models/__init__.py b/models/__init__.py index fbbbe51..fa3cefa 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,2 +1,3 @@ from . import stock_move from . import mrp_production + diff --git a/models/stock_move.py b/models/stock_move.py index e597936..87fef4f 100644 --- a/models/stock_move.py +++ b/models/stock_move.py @@ -9,6 +9,13 @@ class StockMove(models.Model): - The move already has a quantity set (partial consumption). - The move is already picked. """ - if self.quantity > 0: + if self.sudo().quantity > 0 or self.sudo().picked or self.sudo().manual_consumption: return True return super()._should_bypass_set_qty_producing() + + def write(self, vals): + # Enforce manual usage flags if quantity is being set + if 'quantity' in vals and vals['quantity'] > 0: + vals['manual_consumption'] = True + vals['picked'] = True + return super().write(vals)