odoo18/addons_extensions/flutter_odoo/controllers/main.py

56 lines
1.6 KiB
Python

from odoo import http
from odoo.http import request
class MobileArchiveController(http.Controller):
@http.route( '/mobile/archive_record',type='json',auth='user',methods=['POST'],csrf=False)
def archive_record(self, model=None, res_ids=None, archive=True):
if not model or not res_ids:
return {
'status': False,
'message': 'model and res_ids are required'
}
try:
# Ensure list
if not isinstance(res_ids, list):
return {
'status': False,
'message': 'res_ids must be a list'
}
records = request.env[model].sudo().browse(res_ids)
if not records.exists():
return {
'status': False,
'message': 'Records not found'
}
# Check active field exists
if 'active' not in records._fields:
return {
'status': False,
'message': 'Archive not supported for this model'
}
# Archive / Unarchive
records.write({
'active': not archive
})
return {
'status': True,
'message': 'Records archived successfully'
if archive else
'Records unarchived successfully'
}
except Exception as e:
return {
'status': False,
'message': str(e)
}