ii have fastapi api and odoo17 enterprise project and i need one feature, when…
- User
ii have fastapi api and odoo17 enterprise project and i need one feature, when commenting on orders employees user should comment them all and then send it to me, like if user have order that needs 10 employees from service, user should comment and rate them all and then send submit at once, mobile part is in flutter and they are other team, we need to figure out about api for this needs, i will send you some of my files:from typing import Annotated, List, Optional from fastapi import APIRouter, Depends, HTTPException, Request from pydantic import BaseModel from odoo.api import Environment from odoo.addons.fastapi_addon.schemas.base_schema import PagedCollection, Paging from odoo.addons.fastapi_addon.schemas.employee_schema import EmployeeSchema, EmployeeRateRequest, EmployeeRateResponse from ..dependencies import odoo_env, paging from odoo.addons.fastapi_addon.utils.media_url import get_media_url from ..dependencies import odoo_env, paging, get_partner from odoo.addons.base.models.res_partner import Partner from odoo import _
router = APIRouter(tags=["Employees"])
@router.get("/service/{service_id}/employees", response_model=PagedCollection[EmployeeSchema]) async def get_employees_by_service( service_id: int, env: Annotated[Environment, Depends(odoo_env)], request: Request ): """ Get employees related to a specific service along with their ratings. """ # Search for the service record by ID service = env["msk.service"].sudo().search([("id", "=", service_id)], limit=1)
code# Check if the service exists if not service: raise HTTPException(status_code=404, detail=_("Service not found")) # Fetch related employees employees = service.employee_ids count = len(employees) # Prepare employee data with rating calculation items = [] total_rating = 0 total_ratings_count = 0 for employee in employees: # Fetch ratings for each employee ratings = env["employee.rate"].sudo().search([("employee_id", "=", employee.id)]) # Calculate the average rating for the employee employee_rating = 0 if ratings: employee_rating = sum(rating.rate for rating in ratings) / len(ratings) total_rating += employee_rating total_ratings_count += 1 # Append employee data to the list items.append( EmployeeSchema( id=employee.id, full_name=employee.full_name, phone_number=employee.phone_number, avatar=get_media_url(employee._name, employee.id, 'avatar') if employee.avatar else None, is_head_of_staff=employee.is_head_of_staff, gender=employee.gender, average_rating=round(employee_rating, 2) if employee_rating else None, ) ) return PagedCollection[EmployeeSchema]( count=count, current=str(request.url), items=items ) - Assistant