feat: address now is telegram

This commit is contained in:
2024-04-28 19:59:09 +03:00
parent 29d04c848d
commit 4431629cba
5 changed files with 15 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ class ClientDetails(BaseModel):
client_id = Column(Integer, ForeignKey('clients.id'), unique=True, nullable=False, comment='ID клиента') client_id = Column(Integer, ForeignKey('clients.id'), unique=True, nullable=False, comment='ID клиента')
client = relationship('Client', back_populates='details', cascade='all, delete', uselist=False) client = relationship('Client', back_populates='details', cascade='all, delete', uselist=False)
address = Column(String) telegram = Column(String)
phone_number = Column(String) phone_number = Column(String)
inn = Column(String) inn = Column(String)
email = Column(String) email = Column(String)

View File

@@ -17,7 +17,6 @@ class Product(BaseModel):
client_id = Column(Integer, ForeignKey('clients.id'), nullable=False, comment='ID сделки') client_id = Column(Integer, ForeignKey('clients.id'), nullable=False, comment='ID сделки')
client = relationship('Client', back_populates='products') client = relationship('Client', back_populates='products')
barcodes = relationship('ProductBarcode', back_populates='product', cascade="all, delete-orphan") barcodes = relationship('ProductBarcode', back_populates='product', cascade="all, delete-orphan")
my_column = Column(Integer, sequence)
class ProductBarcode(BaseModel): class ProductBarcode(BaseModel):

View File

@@ -7,12 +7,12 @@ from schemas.base import CustomModelCamel, OkMessageSchema
# region Entities # region Entities
class ClientDetailsSchema(CustomModelCamel): class ClientDetailsSchema(CustomModelCamel):
address: str | None = None telegram: str | None = None
phone_number: str | None = None phone_number: str | None = None
inn: str | None = None inn: str | None = None
email: str | None = None email: str | None = None
@field_validator("phone_number", "inn", "email", "address", mode="before") @field_validator("phone_number", "inn", "email", "telegram", mode="before")
def empty_string_to_none(cls, v): def empty_string_to_none(cls, v):
return '' if v is None else v return '' if v is None else v

View File

@@ -83,7 +83,6 @@ class DealCreateRequest(CustomModelCamel):
class DealQuickCreateRequest(CustomModelCamel): class DealQuickCreateRequest(CustomModelCamel):
name: str name: str
client_name: str client_name: str
client_address: str
comment: str comment: str
acceptance_date: datetime.datetime acceptance_date: datetime.datetime
@@ -150,8 +149,8 @@ class DealSummaryReorderRequest(CustomModelCamel):
deal_id: int deal_id: int
status: int status: int
index: int index: int
deadline: datetime.datetime deadline: datetime.datetime | None = None
comment: str comment: str | None = None
class DealDeleteRequest(CustomModelCamel): class DealDeleteRequest(CustomModelCamel):

View File

@@ -83,12 +83,14 @@ class DealService(BaseService):
async def quick_create(self, request: DealQuickCreateRequest, user: User) -> DealQuickCreateResponse: async def quick_create(self, request: DealQuickCreateRequest, user: User) -> DealQuickCreateResponse:
client_service = ClientService(self.session) client_service = ClientService(self.session)
client = await client_service.get_by_name(request.client_name) client = await client_service.get_by_name(request.client_name)
if not client: if not client:
client = await client_service.create_client_raw( client = await client_service.create_client_raw(
user, user,
request.client_name, request.client_name,
ClientDetailsSchema(address=request.client_address)) ClientDetailsSchema()
await client_service.update_details(user, client, ClientDetailsSchema(address=request.client_address)) )
rank = await self._get_rank_for_deal(DealStatus.CREATED) rank = await self._get_rank_for_deal(DealStatus.CREATED)
deal = Deal( deal = Deal(
name=request.name, name=request.name,
@@ -221,8 +223,12 @@ class DealService(BaseService):
is_first = request.index == 0 is_first = request.index == 0
stmt = ( stmt = (
select(Deal) select(Deal)
.where(Deal.current_status == request.status, .where(
Deal.id != request.deal_id) Deal.current_status == request.status,
Deal.id != request.deal_id,
Deal.is_deleted == False,
Deal.is_completed == False
)
.order_by(Deal.lexorank) .order_by(Deal.lexorank)
.offset(max([request.index - 2, 0])) .offset(max([request.index - 2, 0]))
.limit(2 if not is_first else 1) .limit(2 if not is_first else 1)
@@ -232,10 +238,6 @@ class DealService(BaseService):
boundaries = query.scalars().all() boundaries = query.scalars().all()
top_boundary: Union[Deal, None] = boundaries[0] if not is_first else None top_boundary: Union[Deal, None] = boundaries[0] if not is_first else None
bottom_boundary: Union[Deal, None] = boundaries[1] if len(boundaries) == 2 else None bottom_boundary: Union[Deal, None] = boundaries[1] if len(boundaries) == 2 else None
if top_boundary:
print(top_boundary.name)
if bottom_boundary:
print(bottom_boundary.name)
# working when between two elements # working when between two elements
if top_boundary and bottom_boundary: if top_boundary and bottom_boundary:
top_lexorank = lexorank.parse(top_boundary.lexorank) top_lexorank = lexorank.parse(top_boundary.lexorank)