[18.0][FIX] fieldservice_sale: preserve FSM template type#1532
Conversation
|
Hi @wolfhall, @brian10048, @max3903, |
|
The current failing test job is unrelated to this PR's |
|
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! |
|
@fsmw Please do a rebase — the red tests might turn green afterward. |
rrebollo
left a comment
There was a problem hiding this comment.
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.
| @@ -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]) | |||
There was a problem hiding this comment.
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
field-service/fieldservice_sale/models/sale_order.py
Lines 102 to 122 in 9560bf6
| @@ -96,6 +99,7 @@ def _prepare_fsm_values(self, **kwargs): | |||
| "sale_id": kwargs.get("so_id", False), | |||
| "sale_line_id": kwargs.get("sol_id", False), | |||
| "template_id": template_id, | |||
| "type": order_types.id if len(order_types) == 1 else False, | |||
| "company_id": self.company_id.id, | |||
| } | |||
There was a problem hiding this comment.
Originally, it was way too complicated for no reason at all.
82304de to
44ca041
Compare
| vals = self._prepare_fsm_values(so_id=self.id, templates=templates) | ||
| 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}) |
There was a problem hiding this comment.
| new_fsm_sol.write({"fsm_order_id": fsm_by_sale.id}) | |
| new_fsm_sol.fsm_order_id = fsm_by_sale.id |
Fixes #1398
Summary
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