2013-12-16 05:24:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
2013-12-02 12:34:37 +00:00
|
|
|
|
|
|
|
from openerp import SUPERUSER_ID
|
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
|
|
|
from openerp.addons.website.models import website
|
|
|
|
|
2013-12-16 05:24:51 +00:00
|
|
|
|
2013-12-02 12:34:37 +00:00
|
|
|
class sale_quote(http.Controller):
|
2013-12-13 05:09:23 +00:00
|
|
|
def _get_partner_user(self, order_id):
|
|
|
|
order_pool = request.registry.get('sale.order')
|
|
|
|
user_pool = request.registry.get('res.users')
|
|
|
|
partner = order_pool.browse(request.cr, SUPERUSER_ID, order_id, context=request.context).partner_id.id
|
2013-12-16 08:49:35 +00:00
|
|
|
if partner:
|
|
|
|
user = user_pool.search(request.cr, SUPERUSER_ID, [('partner_id', '=', partner)])[0]
|
|
|
|
return user
|
2013-12-13 05:09:23 +00:00
|
|
|
|
2014-01-01 15:47:54 +00:00
|
|
|
@website.route(["/quote/<int:order_id>/<token>"], type='http', auth="public")
|
|
|
|
def view(self, order_id, token, **post):
|
2013-12-20 05:46:36 +00:00
|
|
|
# use SUPERUSER_ID allow to access/view order for public user
|
2014-01-01 15:47:54 +00:00
|
|
|
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
|
|
|
|
assert token == order.access_token, 'Access denied, wrong token!'
|
2014-01-01 20:27:53 +00:00
|
|
|
# TODO: if not order.template_id: return to the URL of the portal view of SO
|
2014-01-01 15:47:54 +00:00
|
|
|
values = {
|
2013-12-16 08:49:35 +00:00
|
|
|
'quotation': order,
|
2014-01-01 15:47:54 +00:00
|
|
|
}
|
2013-12-16 05:24:51 +00:00
|
|
|
return request.website.render('website_sale_quote.so_quotation', values)
|
2013-12-02 12:34:37 +00:00
|
|
|
|
2014-01-01 15:47:54 +00:00
|
|
|
@website.route(['/quote/<int:order_id>/<token>/accept'], type='http', auth="public")
|
|
|
|
def accept(self, order_id, token, **post):
|
|
|
|
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
|
|
|
|
assert token == order.access_token, 'Access denied, wrong token!'
|
2013-12-20 05:46:36 +00:00
|
|
|
request.registry.get('sale.order').write(request.cr, self._get_partner_user(order_id), [order_id], {'state': 'manual'})
|
2014-01-01 19:21:21 +00:00
|
|
|
return request.redirect("/quote/%s/%s" % (order_id, token))
|
2013-12-02 12:34:37 +00:00
|
|
|
|
2013-12-18 12:55:59 +00:00
|
|
|
def decline(self, order_id):
|
2013-12-20 05:46:36 +00:00
|
|
|
return request.registry.get('sale.order').write(request.cr, self._get_partner_user(order_id), [order_id], {'state': 'cancel'})
|
2013-12-02 12:34:37 +00:00
|
|
|
|
2014-01-01 15:47:54 +00:00
|
|
|
@website.route(['/quote/<int:order_id>/<token>/post'], type='http', auth="public")
|
2014-01-01 19:21:21 +00:00
|
|
|
def post(self, order_id, token, **post):
|
2014-01-01 15:47:54 +00:00
|
|
|
# use SUPERUSER_ID allow to access/view order for public user
|
|
|
|
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
|
|
|
|
assert token == order.access_token, 'Access denied, wrong token!'
|
|
|
|
|
2013-12-02 12:34:37 +00:00
|
|
|
if post.get('new_message'):
|
|
|
|
request.session.body = post.get('new_message')
|
2013-12-18 12:55:59 +00:00
|
|
|
if post.get('decline_message'):
|
|
|
|
self.decline(order_id)
|
|
|
|
request.session.body = post.get('decline_message')
|
2013-12-02 12:34:37 +00:00
|
|
|
if 'body' in request.session and request.session.body:
|
2013-12-13 05:09:23 +00:00
|
|
|
request.registry.get('sale.order').message_post(request.cr, self._get_partner_user(order_id), order_id,
|
2013-12-02 12:34:37 +00:00
|
|
|
body=request.session.body,
|
2013-12-18 12:55:59 +00:00
|
|
|
type='comment',
|
2013-12-02 12:34:37 +00:00
|
|
|
subtype='mt_comment',
|
|
|
|
)
|
|
|
|
request.session.body = False
|
2013-12-20 05:46:36 +00:00
|
|
|
return request.redirect("/quote/%s/%s#chat" % (order_id, self._get_token(order_id)))
|
2013-12-02 12:34:37 +00:00
|
|
|
|
2013-12-09 13:10:15 +00:00
|
|
|
@website.route(['/quote/update_line'], type='json', auth="public")
|
2013-12-10 10:44:42 +00:00
|
|
|
def update(self, line_id=None, remove=False, unlink=False, order_id=None, **post):
|
2013-12-09 13:10:15 +00:00
|
|
|
if unlink:
|
2013-12-16 05:24:51 +00:00
|
|
|
return request.registry.get('sale.order.line').unlink(request.cr, SUPERUSER_ID, [int(line_id)], context=request.context)
|
|
|
|
val = self._update_order_line(line_id=int(line_id), number=(remove and -1 or 1))
|
2013-12-10 10:44:42 +00:00
|
|
|
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
|
2013-12-18 12:55:59 +00:00
|
|
|
return [str(val), str(order.amount_total)]
|
2013-12-12 11:50:25 +00:00
|
|
|
|
2013-12-16 05:24:51 +00:00
|
|
|
def _update_order_line(self, line_id, number):
|
2013-12-10 10:44:42 +00:00
|
|
|
order_line_obj = request.registry.get('sale.order.line')
|
2013-12-20 05:46:36 +00:00
|
|
|
order_line_val = order_line_obj.read(request.cr, SUPERUSER_ID, [line_id], [], context=request.context)[0]
|
2013-12-10 10:44:42 +00:00
|
|
|
quantity = order_line_val['product_uom_qty'] + number
|
2013-12-20 05:46:36 +00:00
|
|
|
order_line_obj.write(request.cr, SUPERUSER_ID, [line_id], {'product_uom_qty': (quantity)}, context=request.context)
|
2013-12-10 10:44:42 +00:00
|
|
|
return quantity
|
2014-01-01 15:47:54 +00:00
|
|
|
|
2013-12-16 13:23:46 +00:00
|
|
|
@website.route(["/template/<model('sale.quote.template'):quote>"], type='http', auth="public")
|
|
|
|
def template_view(self, quote=None, **post):
|
2014-01-01 15:47:54 +00:00
|
|
|
quote = request.registry.get('sale.quote.template').browse(request.cr, request.uid, quote.id)
|
|
|
|
values = {
|
2013-12-16 13:23:46 +00:00
|
|
|
'template': quote,
|
2014-01-01 15:47:54 +00:00
|
|
|
}
|
2013-12-16 13:23:46 +00:00
|
|
|
return request.website.render('website_sale_quote.so_template', values)
|
2014-01-02 15:22:25 +00:00
|
|
|
|
|
|
|
@website.route(['/quote/add_line'], type='json', auth="public")
|
|
|
|
def add(self, option=None, order=None, product=None, **post):
|
|
|
|
vals = {}
|
|
|
|
product_obj = request.registry.get('product.product').browse(request.cr, SUPERUSER_ID, int(product), context=request.context)
|
|
|
|
vals.update({
|
|
|
|
'price_unit': product_obj.list_price,
|
|
|
|
'website_description': product_obj.website_description,
|
|
|
|
'name': product_obj.name,
|
|
|
|
'order_id': int(order),
|
|
|
|
'product_id' : product_obj.id,
|
|
|
|
})
|
|
|
|
new = request.registry.get('sale.order.line').create(request.cr, SUPERUSER_ID, vals, context=request.context)
|
|
|
|
request.registry.get('sale.option.line').write(request.cr, SUPERUSER_ID, [int(option)], {'add_to_line': True}, context=request.context)
|
|
|
|
return [new]
|
|
|
|
|