Skip to content

[18.0][ADD] account_analytic_maintenance_stock: Propagate analytic distribution to maintenance stock moves - #950

Open
Ricardo-MC wants to merge 3 commits into
OCA:18.0from
Ricardo-MC:18.0-add-account_analytic_maintenance_stock
Open

[18.0][ADD] account_analytic_maintenance_stock: Propagate analytic distribution to maintenance stock moves#950
Ricardo-MC wants to merge 3 commits into
OCA:18.0from
Ricardo-MC:18.0-add-account_analytic_maintenance_stock

Conversation

@Ricardo-MC

Copy link
Copy Markdown
Contributor

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.

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.
@OCA-git-bot OCA-git-bot added series:18.0 mod:account_analytic_maintenance_stock Module account_analytic_maintenance_stock labels Jul 27, 2026
@Ricardo-MC
Ricardo-MC force-pushed the 18.0-add-account_analytic_maintenance_stock branch from 8292edd to d2774e2 Compare July 27, 2026 21:07

@celm1990 celm1990 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@celm1990 celm1990 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add some tests as well.

@Ricardo-MC
Ricardo-MC force-pushed the 18.0-add-account_analytic_maintenance_stock branch from d2774e2 to 3a63a38 Compare August 5, 2026 22:20
Comment thread account_analytic_maintenance_stock/tests/test_stock_move.py Outdated
@Ricardo-MC
Ricardo-MC force-pushed the 18.0-add-account_analytic_maintenance_stock branch 2 times, most recently from f67f697 to cb61d42 Compare August 18, 2026 21:11
@celm1990

Copy link
Copy Markdown

@celm1990 celm1990 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

Comment thread account_analytic_maintenance_stock/models/stock_move.py Outdated
Comment thread account_analytic_maintenance_stock/tests/test_stock_move.py Outdated
Comment thread account_analytic_maintenance_stock/tests/test_stock_move.py Outdated
Comment on lines +60 to +65
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Suggested change
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"])
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@celm1990
Fixed, Thanks!

@Ricardo-MC
Ricardo-MC force-pushed the 18.0-add-account_analytic_maintenance_stock branch from cb61d42 to 3787d44 Compare August 26, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_analytic_maintenance_stock Module account_analytic_maintenance_stock series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants