Skip to content

[18.0][FIX] fieldservice_sale: preserve FSM template type#1532

Open
fsmw wants to merge 3 commits into
OCA:18.0from
fsmw:18.0-fix-fieldservice-sale-template-type
Open

[18.0][FIX] fieldservice_sale: preserve FSM template type#1532
fsmw wants to merge 3 commits into
OCA:18.0from
fsmw:18.0-fix-fieldservice-sale-template-type

Conversation

@fsmw

@fsmw fsmw commented Apr 30, 2026

Copy link
Copy Markdown

Fixes #1398

Summary

  • Preserve the FSM template on sale-level generated orders when a single template is selected.
  • Copy the template's type to the generated FSM order when the selected templates resolve to one type.
  • Add regression coverage for sale order confirmation creating an FSM order with template and type.

Verification

  • pre-commit run --files fieldservice_sale/models/sale_order.py fieldservice_sale/tests/test_fsm_sale_common.py fieldservice_sale/tests/test_fsm_sale_order.py
  • /home/fsmw/dev/smwlab/.venv/bin/python /home/fsmw/dev/smwlab/OCB/odoo-bin --addons-path=/home/fsmw/dev/smwlab/OCB/odoo/addons,/home/fsmw/dev/smwlab/OCB/addons,/home/fsmw/dev/smwlab/oca-fsmw/field-service -d test_fieldservice_sale_template_type_green3 --init=fieldservice_sale --test-enable --stop-after-init --test-tags /fieldservice_sale --http-port=18073

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @wolfhall, @brian10048, @max3903,
some modules you are maintaining are being modified, check this out!

@fsmw

fsmw commented Apr 30, 2026

Copy link
Copy Markdown
Author

The current failing test job is unrelated to this PR's fieldservice_sale changes. I reproduced the fieldservice_kanban_info failures on clean upstream/18.0 and opened a separate targeted fix in #1533.

@fsmw

fsmw commented May 16, 2026

Copy link
Copy Markdown
Author

CI should now be green after #1533 merged (fixes the upstream date-test flakiness). This is a focused [FIX] preserving FSM template types on SO lines. Ready for review when possible!

@rrebollo

Copy link
Copy Markdown

@fsmw Please do a rebase — the red tests might turn green afterward.

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

Functional and code review: It's working really well.
From a technical perspective, I would personally suggest refactoring to simplify the template_ids approach. Please consider it.

Comment thread fieldservice_sale/models/sale_order.py Outdated
@@ -78,13 +78,16 @@ def _prepare_fsm_values(self, **kwargs):
template_id = kwargs.get("template_id", False)
template_ids = kwargs.get("template_ids", [template_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 did my research. The template_ids keyword argument is misleading. Look at how it's used: the fsm_order_template_id field on sale.order is a many2one, so it always points to a single record — not many.

If You go this way You would need to refactor almost all the method here.

I might be wrong, so please review and consider this. You could even correct it in

def _field_service_generate_sale_fsm_orders(self, new_fsm_sol):
"""
Generate the FSM Order for this sale order if it doesn't exist.
"""
self.ensure_one()
new_fsm_orders = self.env["fsm.order"]
if new_fsm_sol:
fsm_by_sale = self.env["fsm.order"].search(
[("sale_id", "=", self.id), ("sale_line_id", "=", False)]
)
if not fsm_by_sale:
templates = new_fsm_sol.product_id.fsm_order_template_id
vals = self._prepare_fsm_values(
so_id=self.id, template_ids=templates.ids
)
fsm_by_sale = self.env["fsm.order"].sudo().create(vals)
new_fsm_orders |= fsm_by_sale
new_fsm_sol.write({"fsm_order_id": fsm_by_sale.id})
return new_fsm_orders

Comment thread fieldservice_sale/models/sale_order.py
@fsmw fsmw force-pushed the 18.0-fix-fieldservice-sale-template-type branch from 82304de to 44ca041 Compare May 20, 2026 01:01
@OCA-git-bot OCA-git-bot added the mod:fieldservice Module fieldservice label May 20, 2026
Comment thread fieldservice_sale/models/sale_order.py Outdated
@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@max3903 max3903 self-assigned this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template and type are not set on the FSM order created from the sales order

4 participants