# -*- coding: utf-8 -*- from odoo import http from odoo.http import request import werkzeug from odoo.exceptions import UserError from odoo.addons.website_sale.controllers.main import WebsiteSale import json class opendons(http.Controller): @http.route(['/opendons/object'], type='http', auth='public', website=True, sitemap=False,csrf=False) def object(self,model,id,*args,**kw): field_list=request.env[model].sudo().fields_get() objet=request.env[model].search([('id','=',int(id))]) result="" for key in field_list: result=result+str(key)+':'+str(objet[key])+'
' return result @http.route(['/opendons/cp'],type='json', methods=['GET','POST'],auth="public",csrf=False) def index(self, **post): name = post.get('name', False) res={} res['dd']='ggggg' json_object = json.dumps(res, indent = 4) return json_object class SalesProduct(WebsiteSale): @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True) def cart_update(self, product_id, add_qty=1, set_qty=0, **kw): """This route is called when adding a product to cart (no options).""" sale_order = request.website.sale_get_order(force_create=True) if sale_order.state != 'draft': request.session['sale_order_id'] = None sale_order = request.website.sale_get_order(force_create=True) product_custom_attribute_values = None if kw.get('product_custom_attribute_values'): product_custom_attribute_values = json.loads(kw.get('product_custom_attribute_values')) no_variant_attribute_values = None if kw.get('no_variant_attribute_values'): no_variant_attribute_values = json.loads(kw.get('no_variant_attribute_values')) product=request.env['product.product'].search([('id','=',int(product_id))]) donation_amount=0 if 'donation_amount' in kw: donation_amount=int(kw.get('donation_amount')) sale_order._cart_update( product_id=int(product_id), add_qty=add_qty, set_qty=set_qty, product_custom_attribute_values=product_custom_attribute_values, no_variant_attribute_values=no_variant_attribute_values, donation_amount=donation_amount ) if kw.get('express'): return request.redirect("/shop/checkout?express=1") return request.redirect("/shop/cart")