Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0] [IMP] fieldservice_account_analytic: Invoice customer not related to any location #1334

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions fieldservice_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
tracking=True,
)

@api.onchange("location_id")
def _onchange_location_id(self):
self.customer_id = self.location_id.customer_id

Check warning on line 26 in fieldservice_account_analytic/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_account_analytic/models/fsm_order.py#L26

Added line #L26 was not covered by tests

def _compute_total_cost(self):
"""To be overridden as needed from other modules"""
for order in self:
order.total_cost = 0.0

@api.onchange("customer_id")
def _onchange_customer_id_location(self):
Copy link

@BernatObrador BernatObrador Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this onchange can be set like this instead of deleting it:

@api.onchange("customer_id")
def _onchange_customer_id(self):
      if self.customer_id.fsm_location_id:
            self.location_id = self.customer_id.fsm_location_id
      else:
            self.location_id = False

This approach would avoid potential buggy behaviors like:

  1. Creating an FSM order.
  2. Selecting a location.
  3. Changing the customer to one without a location.
  4. Clicking on the Location internal link.
    image

However, I'm not sure if a customer can be delivered to a different location than their own.
What do you think about this approach?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution could be changing the context of the field to let the user freely select the location.

I guess it's just needed to delete this:

<field name="location_id" position="attributes">
                <attribute name="context">{"customer_id": customer_id}</attribute>
</field>

self.location_id = (
self.customer_id.service_location_id if self.customer_id else False
)

def write(self, vals):
res = super().write(vals)
for order in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def test_fsm_orders_1(self):
"name": "Test01",
}
)
order._onchange_customer_id_location()
self.test_location2._onchange_fsm_parent_id_account()
self.env["res.partner"].with_context(location_id=self.test_location2.id).search(
[]
Expand Down