Skip to content

Draft: [14.0][IMP] Make the serial matrix able to produce multiple quantities partially#1754

Draft
ddejong-therp wants to merge 2 commits intoOCA:14.0from
Therp:14.0-make-serial-matrix-failable-inbetween
Draft

Draft: [14.0][IMP] Make the serial matrix able to produce multiple quantities partially#1754
ddejong-therp wants to merge 2 commits intoOCA:14.0from
Therp:14.0-make-serial-matrix-failable-inbetween

Conversation

@ddejong-therp
Copy link
Copy Markdown

@ddejong-therp ddejong-therp commented Mar 16, 2026

Hello,

Here are some changes to the mrp_production_serial_matrix module that make it possible to use the serial matrix wizard to produce multiple quantities at once, each with one of the selected serials, but allowing a part of the quantity to be produced when one fails.

So as an example, when you would like to produce an MO with a quantity of 10, and the 7th product fails to be produced, you would still end up with 6 produced orders, and a backorder for the remaining 4 products.
A message about the exception that just occurred is posted on the backorder.

Now, since this may not be a feature everyone would want to use, I've added a checkbox on the mrp settings page so that it can be enabled if desired.

The real reason that we wanted this implemented, is actually so that the transaction that produces multiple products (with serials), which can become pretty large, doesn't have to lock up Odoo because db tables are locked up for a long period of time.
So after each order is produced for a single product, the db transaction is committed.

class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

allow_manufacturing_exceptions = fields.Boolean("Allow manufacturing exceptions")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field name needs to be prefixed by something like mrp_serial_matrix_ so that it won't conflict with other modules. Eg mrp_serial_matrix_allow_exceptions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I have now renamed the config parameter.

.get_param("mrp_production_serial_matrix.allow_manufacturing_exceptions")
)
res["allow_manufacturing_exceptions"] = value
return res
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to do this, there is a shortcut:

    my_custom_setting = fields.Boolean(
        string="Enable My Custom Feature",
        config_parameter='my_module.my_custom_setting'
    )

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I didn't realize this was already possible in 14.0
Changed it now.

white-space: pre }

span.problematic {
span.problematic, pre.problematic {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes like this need to be branched into a separate pre-commit fixes commit, and the functional changes in another squashed commit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I have squashed all the commits, and removed these pre-commit changes.
I will add these later again when all other changes are done.

except Exception as e:
exceptions_allowed = self.env["ir.config_parameter"].get_param(
"mrp_production_serial_matrix.allow_manufacturing_exceptions"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config parameter should already be fetched outside of the loop, not upon catching the exception itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one. Fixed that.

}
else:
break
raise e
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner is to do

if not exceptions_allowed:
    raise
# handle exception

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.
Fixed this as well.

finished_count += 1
if no_backorders:
break
except Exception as e:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it's wrong to catch exceptions outside the whole loop - we should:

  1. loop
  2. inside the loop, place a try that catches exception
  3. if exception, handle
  4. if no exception, commit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.
Can you explain what the benefit of this is though?
Thanks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'm actually not sure if it's needed to place the try/except inside the loop.

I guess it's only needed if you want to know on which serial or which MO it failed.

If the except is outside of the loop block those variables are lost.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case we do need to break the loop once an exception has happened. In the way you've done it currently, an explicit break is not necessary

if exceptions_allowed and finished_count > 0:
_logger.error(e)
message = _(
"Not all orders where produced because an exception occurred: "
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, fixed it.

@ddejong-therp ddejong-therp changed the title [14.0][IMP] Make the serial matrix able to produce multiple quantities partially Draft: [14.0][IMP] Make the serial matrix able to produce multiple quantities partially Mar 19, 2026
@ddejong-therp ddejong-therp marked this pull request as draft March 19, 2026 09:26
"mrp_production_serial_matrix.allow_manufacturing_exceptions"
)
if exceptions_allowed and finished_count > 0:
_logger.error(e)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually also need a self.env.cr.rollback() here because otherwise, the modifications of the last call of which the exception was caught, may still get committed, since we are catching the exception.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, very fair. Fixed it.

@ddejong-therp ddejong-therp force-pushed the 14.0-make-serial-matrix-failable-inbetween branch 3 times, most recently from b02eae3 to d51d063 Compare March 20, 2026 15:53
still produce a part of the products, when one of them fails.
@ddejong-therp ddejong-therp force-pushed the 14.0-make-serial-matrix-failable-inbetween branch from d51d063 to 3754c6f Compare March 20, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants