Skip to content
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
15 changes: 8 additions & 7 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ def create(self, vals):
is_button = fields.Boolean(default=False)

def write(self, vals):
if vals.get("stage_id", False) and vals.get("is_button", False):
vals["is_button"] = False
else:
stage_id = self.env["fsm.stage"].browse(vals.get("stage_id"))
if stage_id == self.env.ref("fieldservice.fsm_stage_completed"):
raise UserError(_("Cannot move to completed from Kanban"))
self._calc_scheduled_dates(vals)
for record in self:
if vals.get("stage_id", False) and vals.get("is_button", False):
vals["is_button"] = False
Copy link
Member

Choose a reason for hiding this comment

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

get(x, False) is redundant, as the default result for a missing key is already a falsy value.
Does this if need to be inside the loop? It doesn't make any use of the iterated record.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

I do not change the write logic, just solved an error when you try to mass update records that was throwing an expected singleton error.

I just added for record in self, and change the self._calc_scheduled_dates(vals) for record._calc_scheduled_dates(vals) to avoid that.

If you want, I can do this too, but it wasn't the main goal.

else:
stage_id = self.env["fsm.stage"].browse(vals.get("stage_id"))
if stage_id == self.env.ref("fieldservice.fsm_stage_completed"):
raise UserError(_("Cannot move to completed from Kanban"))
record._calc_scheduled_dates(vals)
res = super().write(vals)
return res

Expand Down
5 changes: 3 additions & 2 deletions fieldservice/tests/test_fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ def test_fsm_order(self):
)
)
self.assertTrue(data, "It should be able to read group")
self.Order.write(
new_order = order.copy()
new_order.write(
{
"location_id": self.test_location.id,
"stage_id": self.stage1.id,
"is_button": True,
}
)
with self.assertRaises(UserError):
self.Order.write(
new_order.write(
{
"location_id": self.test_location.id,
"stage_id": self.stage1.id,
Expand Down
Loading