ebanutsya
This commit is contained in:
		@@ -33,3 +33,10 @@
 | 
				
			|||||||
10-28 05:08 - assemblr - INFO - SiproClient successfully initialized
 | 
					10-28 05:08 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
10-28 05:09 - assemblr - INFO - SiproClient successfully initialized
 | 
					10-28 05:09 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
10-28 05:09 - assemblr - INFO - SiproClient successfully initialized
 | 
					10-28 05:09 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 01:50 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 01:50 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 02:21 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 02:25 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 06:43 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 06:47 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 | 
					10-29 06:53 - assemblr - INFO - SiproClient successfully initialized
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,13 @@ class Assembly(db.Model):
 | 
				
			|||||||
    id = db.Column(db.Integer, primary_key=True, comment='ID сборки')
 | 
					    id = db.Column(db.Integer, primary_key=True, comment='ID сборки')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    created_at = db.Column(db.DateTime, nullable=False, comment='Дата и время начала сборки')
 | 
					    created_at = db.Column(db.DateTime, nullable=False, comment='Дата и время начала сборки')
 | 
				
			||||||
    ended_at = db.Column(db.DateTime, nullable=False, comment='Дата и время конца сборки')
 | 
					    ended_at = db.Column(db.DateTime, nullable=True, comment='Дата и время конца сборки')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
 | 
					    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
 | 
				
			||||||
    user = db.relationship('User', backref='assemblies')
 | 
					    user = db.relationship('User', backref='assemblies')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    order_id = db.Column(db.Integer, nullable=False, comment='ID заказа в базе данных')
 | 
					    order_id = db.Column(db.Integer, nullable=False, comment='ID заказа в базе данных')
 | 
				
			||||||
 | 
					    active = db.Column(db.Boolean, nullable=False, comment='Активная ли сборка')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Barcode(db.Model):
 | 
					class Barcode(db.Model):
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										47
									
								
								routes/assembly.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								routes/assembly.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					import datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from flask import Blueprint, request, jsonify
 | 
				
			||||||
 | 
					from flask_jwt_extended import get_jwt_identity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import database
 | 
				
			||||||
 | 
					from routes.utils import jwt_protect_blueprint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					assembly_blueprint = jwt_protect_blueprint(Blueprint('assembly', __name__))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@assembly_blueprint.post('/open')
 | 
				
			||||||
 | 
					def create_assembly():
 | 
				
			||||||
 | 
					    data: dict = request.json
 | 
				
			||||||
 | 
					    order_id: int = data.get('orderId')
 | 
				
			||||||
 | 
					    user_id = get_jwt_identity()
 | 
				
			||||||
 | 
					    existing_assembly = database.Assembly.query.filter_by(order_id=order_id).first()
 | 
				
			||||||
 | 
					    if existing_assembly:
 | 
				
			||||||
 | 
					        response = {
 | 
				
			||||||
 | 
					            'ok': False,
 | 
				
			||||||
 | 
					            'message': 'Сборка этого товара уже была запущена',
 | 
				
			||||||
 | 
					            'assemblyId': existing_assembly.id,
 | 
				
			||||||
 | 
					            'statusCode': 'ASSEMBLY_ALREADY_EXISTS'
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return jsonify(response)
 | 
				
			||||||
 | 
					    active_assembly = database.Assembly.query.filter_by(user_id=user_id).first()
 | 
				
			||||||
 | 
					    if active_assembly:
 | 
				
			||||||
 | 
					        response = {
 | 
				
			||||||
 | 
					            'ok': False,
 | 
				
			||||||
 | 
					            'message': 'Вы не можете запустить сборку заказа, так как у вас уже есть активная сборка',
 | 
				
			||||||
 | 
					            'assemblyId': active_assembly.id,
 | 
				
			||||||
 | 
					            'statusCode': 'USER_ALREADY_HAS_ACTIVE_ASSEMBLY'
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return jsonify(response)
 | 
				
			||||||
 | 
					    assembly = database.Assembly(created_at=datetime.datetime.now(),
 | 
				
			||||||
 | 
					                                 user_id=user_id,
 | 
				
			||||||
 | 
					                                 order_id=order_id,
 | 
				
			||||||
 | 
					                                 active=True)
 | 
				
			||||||
 | 
					    database.db.session.add(assembly)
 | 
				
			||||||
 | 
					    database.db.session.commit()
 | 
				
			||||||
 | 
					    response = {
 | 
				
			||||||
 | 
					        'ok': True,
 | 
				
			||||||
 | 
					        'message': 'Сборка успешно запущена!',
 | 
				
			||||||
 | 
					        'assemblyId': assembly.id,
 | 
				
			||||||
 | 
					        'statusCode': 'CREATED'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return jsonify(response)
 | 
				
			||||||
@@ -9,4 +9,5 @@ barcode_blueprint = jwt_protect_blueprint(Blueprint('barcode', __name__))
 | 
				
			|||||||
def search_product():
 | 
					def search_product():
 | 
				
			||||||
    args = request.args
 | 
					    args = request.args
 | 
				
			||||||
    barcode = args.get('barcode')
 | 
					    barcode = args.get('barcode')
 | 
				
			||||||
    return sipro.api.barcode.get_products_by_barcode(barcode)
 | 
					    response = sipro.api.barcode.get_products_by_barcode(barcode)
 | 
				
			||||||
 | 
					    return response
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user