|
|
|
|
@ -4,8 +4,9 @@ import pandas as pd
|
|
|
|
|
from django.contrib.gis.measure import Distance
|
|
|
|
|
from django.db.models import F
|
|
|
|
|
|
|
|
|
|
from postamates.settings import POINT_RADIUS
|
|
|
|
|
from postamates.settings import DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS
|
|
|
|
|
from service import models
|
|
|
|
|
from service.enums import PointStatus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PointService:
|
|
|
|
|
@ -20,16 +21,16 @@ class PointService:
|
|
|
|
|
@staticmethod
|
|
|
|
|
def update_points_in_radius(qs: models.PlacementPoint, new_status: str):
|
|
|
|
|
for point in qs:
|
|
|
|
|
if new_status == 'Installation':
|
|
|
|
|
if point.status == 'Pending':
|
|
|
|
|
if new_status == PointStatus.Installation.name:
|
|
|
|
|
if point.status == PointStatus.Pending.name:
|
|
|
|
|
pnts = models.PlacementPoint.objects.filter(
|
|
|
|
|
geometry__distance_lt=(point.geometry, Distance(m=POINT_RADIUS)),
|
|
|
|
|
geometry__distance_lt=(point.geometry, Distance(m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS)),
|
|
|
|
|
)
|
|
|
|
|
pnts.update(target_post_cnt=F('target_post_cnt') + 1)
|
|
|
|
|
elif new_status == 'Cancelled' or new_status == 'Pending':
|
|
|
|
|
if point.status == 'Installation':
|
|
|
|
|
elif new_status == PointStatus.Cancelled.name or new_status == PointStatus.Pending.name:
|
|
|
|
|
if point.status == PointStatus.Installation.name:
|
|
|
|
|
pnts = models.PlacementPoint.objects.filter(
|
|
|
|
|
geometry__distance_lt=(point.geometry, Distance(m=POINT_RADIUS)),
|
|
|
|
|
geometry__distance_lt=(point.geometry, Distance(m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS)),
|
|
|
|
|
)
|
|
|
|
|
pnts.update(target_post_cnt=F('target_post_cnt') - 1 if F('target_post_cnt') != 0 else 0)
|
|
|
|
|
|
|
|
|
|
|