Skip to content

Commit

Permalink
Merge pull request #33 from Build-Squad/Gen-74-Update-Serice-Master-/…
Browse files Browse the repository at this point in the history
…-Service-Models

Gen 74 update serice master / service models
  • Loading branch information
muditmahajan authored Dec 11, 2023
2 parents cbbcb86 + 3811d3d commit 4eab492
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 226 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.7 on 2023-12-11 06:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('packages', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='service',
name='end_date',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='service',
name='start_date',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='servicemaster',
name='is_duration_based',
field=models.BooleanField(default=False),
),
]
3 changes: 3 additions & 0 deletions src/api/marketplace/packages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ServiceMaster(models.Model):
type = models.CharField(choices=TYPE_CHOICES, max_length=50, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
deleted_at = models.DateTimeField(blank=True, null=True)
is_duration_based = models.BooleanField(default=False)

class Meta:
db_table = "service_master"
Expand All @@ -68,6 +69,8 @@ class Service(models.Model):
status = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
deleted_at = models.DateTimeField(blank=True, null=True)
start_date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)
class Meta:
db_table = "service"

Expand Down
22 changes: 21 additions & 1 deletion src/api/marketplace/packages/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,24 @@ class CreateServicesSerializer(serializers.ModelSerializer):
class Meta:
model = Service
fields = '__all__'
# fields = ('id', 'service_master', 'package', 'quantity', 'price', 'currency', 'status'
# fields = ('id', 'service_master', 'package', 'quantity', 'price', 'currency', 'status'

def validate(self, data):
service_master = data.get('service_master')
start_date = data.get('start_date')
end_date = data.get('end_date')

# If service_master is just the ID, retrieve the ServiceMaster instance
if isinstance(service_master, int):
service_master = ServiceMaster.objects.get(id=service_master)

if service_master.is_duration_based:
if start_date is None or end_date is None:
raise serializers.ValidationError(
"Start date and end date cannot be empty")
else:
if start_date is not None or end_date is not None:
raise serializers.ValidationError(
"Service Master is not duration based. Start date and end date should be empty")

return data
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ import { FORM_DATE_FORMAT, PACKAGE_STATUS } from "@/src/utils/consts";
import CloseIcon from "@mui/icons-material/Close";
import {
Autocomplete,
Box,
Button,
Grid,
IconButton,
Modal,
TextField,
Typography,
Typography
} from "@mui/material";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import dayjs from "dayjs";
import { FormikValues, useFormik } from "formik";
import React, { useEffect } from "react";
import { packageFormInitialValues, packageFormSchema } from "./validation";
import CustomAutoComplete from "../../shared/customAutoComplete";
import CustomModal from "../../shared/customModal";
import { notification } from "../../shared/notification";
import CustomAutoComplete from "../../shared/customAutoComplete";
import dayjs from "dayjs";
import { packageFormInitialValues, packageFormSchema } from "./validation";

type CreateUpdatePackageProps = {
packageItem?: PackageType | null;
Expand Down
Loading

0 comments on commit 4eab492

Please sign in to comment.