So I am trying to create a lot, so far the code works in my odoo community version on local development. But when I deploy it on odoo sh, it keeps saying Record does not exist for product.
Notes:
1. The product exists. I have a separate endpoint listing and getting the product.
2. I tried changing user access, the error is the same.
On local development with community version odoo, I can't replicate it. The error shows only when I have deployed it to odoo sh.
I need help. Thank you.
def create_lot(self):
try:
data = json.loads(http.request.httprequest.data)
product_id = data["product_id"]
po_name = data["po_name"]
company_id = data["company_id"]
product = request.env['product.template'].sudo().browse(product_id)
ref = product.name[:12]
if product.default_code:
ref = product.default_code
# Create a new lot
lot_data = {
'name': f'{po_name}-{ref}',
'display_name': f'{po_name}-{ref}',
'product_id': product_id,
'company_id': company_id,
}
lot = request.env['stock.lot'].sudo().create(lot_data)
lot_serializer = Lot()
lot_serialized = lot_serializer.get_one(lot.id)
return response_template( status_code=200, status="success", data=lot_serialized )
except KeyError as e:
return response_template( status_code=500, status="error", data=f'Missing required data: {e}' )
except Exception as e:
return response_template( status_code=500, status="error", data=str(e) )