Harden zone polygon validation for safe upgrades
This commit is contained in:
@@ -15,7 +15,6 @@ class RepairFsmZone(models.Model):
|
||||
code = fields.Char(tracking=True)
|
||||
polygon_geojson = fields.Text(
|
||||
string="Polygon (GeoJSON)",
|
||||
required=True,
|
||||
tracking=True,
|
||||
help="GeoJSON Polygon geometry. Coordinates order: [longitude, latitude].",
|
||||
)
|
||||
@@ -35,6 +34,10 @@ class RepairFsmZone(models.Model):
|
||||
return [key for key, _label in self._fields["state"].selection]
|
||||
|
||||
def action_set_active(self):
|
||||
for rec in self:
|
||||
if not rec.polygon_geojson:
|
||||
raise ValidationError("Polygon is required before activating the FSM Zone.")
|
||||
rec._extract_polygon_points()
|
||||
self.write({"state": "active", "active": True})
|
||||
|
||||
def action_archive(self):
|
||||
@@ -59,6 +62,8 @@ class RepairFsmZone(models.Model):
|
||||
|
||||
def _extract_polygon_points(self):
|
||||
self.ensure_one()
|
||||
if not self.polygon_geojson:
|
||||
raise ValidationError("Polygon is required.")
|
||||
try:
|
||||
data = json.loads(self.polygon_geojson or "")
|
||||
except json.JSONDecodeError as exc:
|
||||
@@ -95,6 +100,8 @@ class RepairFsmZone(models.Model):
|
||||
self.ensure_one()
|
||||
if latitude is None or longitude is None:
|
||||
return False
|
||||
if not self.polygon_geojson:
|
||||
return False
|
||||
points = self._extract_polygon_points()
|
||||
return self._point_in_polygon(float(longitude), float(latitude), points)
|
||||
|
||||
@@ -117,4 +124,5 @@ class RepairFsmZone(models.Model):
|
||||
@api.constrains("polygon_geojson")
|
||||
def _check_polygon_geojson(self):
|
||||
for rec in self:
|
||||
if rec.polygon_geojson:
|
||||
rec._extract_polygon_points()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<header>
|
||||
<button name="action_confirm" type="object" string="Confirm" class="btn-primary" invisible="state != 'draft'"/>
|
||||
<button name="action_assign_to_me" type="object" string="Assign to me" class="btn-primary" invisible="state not in ('confirmed','assigned')"/>
|
||||
<button name="action_detect_zone" type="object" string="Detect Zone" invisible="not service_latitude or not service_longitude"/>
|
||||
<button name="action_detect_zone" type="object" string="Detect Zone" invisible="service_latitude == False or service_longitude == False"/>
|
||||
<button name="action_start" type="object" string="Start" invisible="state != 'assigned'"/>
|
||||
<button name="action_done" type="object" string="Done" class="btn-primary" invisible="state not in ('in_progress','assigned')"/>
|
||||
<button name="action_cancel" type="object" string="Cancel" invisible="state in ('done','cancelled')"/>
|
||||
|
||||
Reference in New Issue
Block a user