Draft: [14.0][IMP] Make the serial matrix able to produce multiple quantities partially#1754
Draft: [14.0][IMP] Make the serial matrix able to produce multiple quantities partially#1754ddejong-therp wants to merge 2 commits intoOCA:14.0from
Conversation
| class ResConfigSettings(models.TransientModel): | ||
| _inherit = "res.config.settings" | ||
|
|
||
| allow_manufacturing_exceptions = fields.Boolean("Allow manufacturing exceptions") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Alright, I have now renamed the config parameter.
| .get_param("mrp_production_serial_matrix.allow_manufacturing_exceptions") | ||
| ) | ||
| res["allow_manufacturing_exceptions"] = value | ||
| return res |
There was a problem hiding this comment.
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'
)
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Changes like this need to be branched into a separate pre-commit fixes commit, and the functional changes in another squashed commit
There was a problem hiding this comment.
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" | ||
| ) |
There was a problem hiding this comment.
This config parameter should already be fetched outside of the loop, not upon catching the exception itself.
| } | ||
| else: | ||
| break | ||
| raise e |
There was a problem hiding this comment.
Cleaner is to do
if not exceptions_allowed:
raise
# handle exception
There was a problem hiding this comment.
Indeed.
Fixed this as well.
| finished_count += 1 | ||
| if no_backorders: | ||
| break | ||
| except Exception as e: |
There was a problem hiding this comment.
Actually I think it's wrong to catch exceptions outside the whole loop - we should:
- loop
- inside the loop, place a try that catches exception
- if exception, handle
- if no exception, commit
There was a problem hiding this comment.
Alright.
Can you explain what the benefit of this is though?
Thanks.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: " |
| "mrp_production_serial_matrix.allow_manufacturing_exceptions" | ||
| ) | ||
| if exceptions_allowed and finished_count > 0: | ||
| _logger.error(e) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, very fair. Fixed it.
b02eae3 to
d51d063
Compare
still produce a part of the products, when one of them fails.
d51d063 to
3754c6f
Compare
Hello,
Here are some changes to the
mrp_production_serial_matrixmodule 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.