[18.0][ADD] account_analytic_maintenance_stock: Propagate analytic distribution to maintenance stock moves - #950
Conversation
Propagate analytic distribution to maintenance stock moves. When stock moves are linked to maintenance equipment through the maintenance_stock module, this module propagates the analytic distribution configured on the equipment to the stock move. The implementation is intentionally limited to stock moves related to maintenance equipment and only fills the analytic distribution when it has not already been set, preserving values provided by other modules. Currently maintenance_stock does not provide a dedicated hook to initialize stock move values, so this module overrides create() with a narrowly scoped implementation.
8292edd to
d2774e2
Compare
celm1990
left a comment
There was a problem hiding this comment.
LGTM, but couldn't this be assigned before the record is created?
This would avoid triggering a write immediately after create and optimize the flow.
For example, you could retrieve the default_maintenance_request_id from the context in default_get or use a similar approach.
d2774e2 to
3a63a38
Compare
f67f697 to
cb61d42
Compare
celm1990
left a comment
There was a problem hiding this comment.
@Ricardo-MC, please review my comments. I think this is a better approach, and the user will see the analytic distribution immediately instead of only after saving the record.
| picking_form = Form( | ||
| self.env["stock.picking"].with_context( | ||
| default_maintenance_request_id=self.request.id, | ||
| ) | ||
| ) | ||
| picking_form.picking_type_id = self.maintenance_warehouse.cons_type_id |
There was a problem hiding this comment.
I think you should use the context from the action action_view_stock_picking_ids: https://github.com/OCA/maintenance/blob/33ae57cec76a3884a01e9567ef3c8d7386022cff/maintenance_stock/models/maintenance_request.py#L25
| picking_form = Form( | |
| self.env["stock.picking"].with_context( | |
| default_maintenance_request_id=self.request.id, | |
| ) | |
| ) | |
| picking_form.picking_type_id = self.maintenance_warehouse.cons_type_id | |
| action = self.request.action_view_stock_picking_ids() | |
| picking_form = Form( | |
| self.env["stock.picking"].with_context(**action["context"]) | |
| ) |
cb61d42 to
3787d44
Compare
When stock moves are linked to maintenance equipment through the
maintenance_stock module, this module propagates the analytic
distribution configured on the equipment to the stock move.
The implementation is intentionally limited to stock moves related to
maintenance equipment and only fills the analytic distribution when it
has not already been set, preserving values provided by other modules.
Currently maintenance_stock does not provide a dedicated hook to
initialize stock move values, so this module overrides create() with a
narrowly scoped implementation.