From b6fa0fbce6e575dd46866fc9775feb2facf8dd04 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 28 Feb 2023 11:09:05 +0100 Subject: [PATCH] [FIX][14.0] fieldservice_sale_recurring: make link between invoice and fsm order for recurring order --- fieldservice_sale_recurring/__manifest__.py | 1 + .../models/fsm_recurring.py | 5 +++++ .../models/sale_order_line.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/fieldservice_sale_recurring/__manifest__.py b/fieldservice_sale_recurring/__manifest__.py index 2948aeea9b..17881a44fb 100644 --- a/fieldservice_sale_recurring/__manifest__.py +++ b/fieldservice_sale_recurring/__manifest__.py @@ -11,6 +11,7 @@ "depends": [ "fieldservice_recurring", "fieldservice_sale", + "fieldservice_account", ], "data": [ "security/ir.model.access.csv", diff --git a/fieldservice_sale_recurring/models/fsm_recurring.py b/fieldservice_sale_recurring/models/fsm_recurring.py index 8f1489a2b4..1503c69221 100644 --- a/fieldservice_sale_recurring/models/fsm_recurring.py +++ b/fieldservice_sale_recurring/models/fsm_recurring.py @@ -20,3 +20,8 @@ def action_view_sales(self): "context": {"create": False}, "name": _("Sales Orders"), } + + def _prepare_order_values(self, date=None): + res = super()._prepare_order_values(date) + res["sale_line_id"] = self.sale_line_id.id + return res diff --git a/fieldservice_sale_recurring/models/sale_order_line.py b/fieldservice_sale_recurring/models/sale_order_line.py index 5df15da18a..01ac57e3db 100644 --- a/fieldservice_sale_recurring/models/sale_order_line.py +++ b/fieldservice_sale_recurring/models/sale_order_line.py @@ -68,3 +68,21 @@ def _field_create_fsm_recurring(self): fsm_recurring.message_post(body=fsm_recurring_msg) result[so_line.id] = fsm_recurring return result + + def _get_invoiceable_fsm_order_domain(self): + """ + add fsm_recurring_id to domain + :return: + """ + dom = super()._get_invoiceable_fsm_order_domain() + if self.fsm_recurring_id: + dom.append(("fsm_recurring_id", "=", self.fsm_recurring_id.id)) + return dom + + def _prepare_invoice_line(self, **optional_values): + res = super()._prepare_invoice_line(**optional_values) + if self.fsm_recurring_id: + fsm_orders = self._get_invoiceable_fsm_order() + if fsm_orders: + res.update({"fsm_order_ids": [(6, 0, fsm_orders.ids)]}) + return res