Skip to content

Commit

Permalink
[14.0][FIX]- fieldservice_accont_analytic - write correctly customer_…
Browse files Browse the repository at this point in the history
…id and the actual customer when sale_id is present
  • Loading branch information
michelerusti committed May 18, 2023
1 parent ff676b8 commit 58f3cc9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 3 additions & 4 deletions fieldservice_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions fieldservice_sale/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 1 addition & 3 deletions fieldservice_stock_account/tests/test_fsm_stock_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import datetime

from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -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()

0 comments on commit 58f3cc9

Please sign in to comment.