OdooDigitizationService/addons/tx_cms/controllers/fine_service.py

106 lines
4.3 KiB
Python

# -*- coding: utf-8 -*-
import logging
from odoo import http, tools
from .tool import MakeResponse
_logger = logging.getLogger(__name__)
class fineService(http.Controller):
@http.route(['/fine_service'], type='http', auth="public",
website=True)
def list(self, **kw):
return http.request.render('tx_cms.fineService')
@http.route(['/fine_service_data', '/fine_service_data/page/<int:page>'], type='http', auth="public",
website=True)
def listData(self, characteristic_id=0, technical_id=0, industry_id=0, page=1, **kw):
service_obj = http.request.env["tx.fine.service"].sudo()
_post_per_page = 9
page = int(page)
characteristicList = []
technicalList = []
industryList = []
characteristic_id = int(characteristic_id)
technical_id = int(technical_id)
industry_id = int(industry_id)
characteristic_ids = service_obj.characteristic_ids.sudo().search([("code", "=", "CP")])._get_dict_values()
for index, item in enumerate(characteristic_ids):
item["active"] = True if item["id"] == characteristic_id else False
characteristicList.append(item)
technical_ids = service_obj.technical_ids.sudo().search([("code", "=", "TF")])._get_dict_values()
for index, item in enumerate(technical_ids):
item["active"] = True if item["id"] == technical_id else False
technicalList.append(item)
industry_ids = service_obj.industry_ids.sudo().search([("code", "=", "TF")])._get_dict_values()
for index, item in enumerate(industry_ids):
item["active"] = True if item["id"] == industry_id else False
industryList.append(item)
domain = []
if industry_id:
domain.append(("industry_ids", "in", [industry_id]))
if technical_id:
domain.append(("technical_ids", "in", [technical_id]))
if characteristic_id:
domain.append(("characteristic_ids", "in", [characteristic_id]))
serviceAll = service_obj.search(domain)
pager = tools.lazy(
lambda: http.request.website.pager(url='/fine_service_data', total=serviceAll.__len__(),
page=page, step=_post_per_page, scope=_post_per_page,
url_args=kw))
serviceData = serviceAll[
(page - 1) * _post_per_page:page * _post_per_page]
records = []
for service in serviceData:
records.append({
"id": service.id,
"recommend": service.recommend,
"imgUrl": http.request.website.image_url(service, 'img'),
"name": service.name,
"companyName": service.company_name,
"createDate": f"""{service.create_date.year}{service.create_date.month}{service.create_date.day}""",
"briefIntroduction": str(service.brief_introduction),
"technicalIds": [technical_id.name for technical_id in service.technical_ids]
})
return MakeResponse.success({
"characteristicList": characteristicList,
"technicalList": technicalList,
"industryList": industryList,
"records": records,
"characteristic_id": characteristic_id,
"technical_id": technical_id,
"industry_id": industry_id,
"pager": pager._value,
})
@http.route('/fine_service_details/<model("tx.fine.service"):obj>', type='http', auth="public",
website=True)
def object(self, obj, **kw):
return http.request.render('tx_cms.fineServiceDetails', {
'object': obj
})
@http.route('/fine_service/details', methods=['get'], auth='public', website=True)
def record_details(self, recordId, **kw):
record_obj = http.request.env["tx.fine.service"].sudo()
obj = record_obj.sudo().browse([int(recordId)])
return MakeResponse.success({
"name": obj.name,
"briefIntroduction": obj.brief_introduction,
"technicalList": [technical_id.name for technical_id in obj.technical_ids],
"imgUrl": http.request.website.image_url(obj, 'img'),
"companyName": obj.company_name,
"content": obj.content,
})