From 58f3cc9325341f99fb00b9a7eb81c6b5d868d798 Mon Sep 17 00:00:00 2001 From: michelerusti Date: Wed, 10 May 2023 17:30:14 +0200 Subject: [PATCH] [14.0][FIX]- fieldservice_accont_analytic - write correctly customer_id and the actual customer when sale_id is present --- fieldservice_account_analytic/models/fsm_order.py | 7 +++---- fieldservice_sale/models/fsm_order.py | 12 ++++++++++++ .../tests/test_fsm_stock_account.py | 4 +--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fieldservice_account_analytic/models/fsm_order.py b/fieldservice_account_analytic/models/fsm_order.py index daacfa0900..70ce44d587 100644 --- a/fieldservice_account_analytic/models/fsm_order.py +++ b/fieldservice_account_analytic/models/fsm_order.py @@ -56,8 +56,7 @@ def _onchange_customer_id_location(self): self.location_id = self.customer_id.service_location_id def write(self, vals): - res = super(FSMOrder, self).write(vals) for order in self: - if "customer_id" not in vals and order.customer_id is False: - order.customer_id = order.location_id.customer_id.id - return res + if "customer_id" not in vals and not order.customer_id: + vals.update({"customer_id": order.location_id.customer_id.id}) + return super(FSMOrder, self).write(vals) diff --git a/fieldservice_sale/models/fsm_order.py b/fieldservice_sale/models/fsm_order.py index b9dbcaaf1c..2ef38b4413 100644 --- a/fieldservice_sale/models/fsm_order.py +++ b/fieldservice_sale/models/fsm_order.py @@ -20,3 +20,15 @@ def action_view_sales(self): "context": {"create": False}, "name": _("Sales Orders"), } + + def write(self, vals): + for order in self: + if "customer_id" not in vals and not order.customer_id: + vals.update({"customer_id": order.sale_id.partner_id.id}) + return super(FSMOrder, self).write(vals) + + def create(self, vals): + sale_id = self.env['sale.order'].browse(vals.get("sale_id")) + if sale_id: + vals["customer_id"] = sale_id.partner_id.id + return super(FSMOrder, self).create(vals) diff --git a/fieldservice_stock_account/tests/test_fsm_stock_account.py b/fieldservice_stock_account/tests/test_fsm_stock_account.py index bd3bf35ceb..f3c7205154 100644 --- a/fieldservice_stock_account/tests/test_fsm_stock_account.py +++ b/fieldservice_stock_account/tests/test_fsm_stock_account.py @@ -3,7 +3,6 @@ import datetime -from odoo.exceptions import UserError from odoo.tests.common import TransactionCase @@ -77,7 +76,6 @@ def test_fsm_order(self): SR_2.action_confirm() fsm_order2.account_no_invoice() fsm_order2.bill_to = "contact" - with self.assertRaises(UserError): - fsm_order2.account_no_invoice() + fsm_order2.account_no_invoice() fsm_order2.customer_id = self.test_partner.id fsm_order2.account_no_invoice()