[IMP] website_quote: use website_mail generic chatter

This commit is contained in:
Damien Bouvy
2015-08-07 01:47:06 +02:00
committed by Antony Lesuisse
parent ad081b0da1
commit 4aa3658adb
3 changed files with 14 additions and 60 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ OpenERP Sale Quote Roller
""",
'author': 'OpenERP SA',
'depends': ['website', 'sale', 'mail', 'web_tip', 'payment', 'website_portal'],
'depends': ['website', 'sale', 'mail', 'web_tip', 'payment', 'website_portal_sale', 'website_mail'],
'data': [
'quotation_report.xml',
'views/website_quotation.xml',
+7 -32
View File
@@ -9,6 +9,8 @@ import datetime
import time
from openerp.tools.translate import _
from openerp.addons.website_mail.controllers.main import _message_post_helper
class sale_quote(http.Controller):
@http.route([
@@ -28,7 +30,7 @@ class sale_quote(http.Controller):
if request.session.get('view_quote',False)!=now:
request.session['view_quote'] = now
body=_('Quotation viewed by customer')
self.__message_post(body, order_id, message_type='comment')
_message_post_helper(res_model='sale.order', res_id=order.id, message=body, token=token, token_field="access_token", message_type='notification')
days = 0
if order.validity_date:
days = (datetime.datetime.strptime(order.validity_date, '%Y-%m-%d') - datetime.datetime.now()).days + 1
@@ -51,7 +53,8 @@ class sale_quote(http.Controller):
'tx_id': tx_id,
'tx_state': tx.state if tx else False,
'tx_post_msg': tx.acquirer_id.post_msg if tx else False,
'need_payment': not tx_id and order.state == 'manual'
'need_payment': not tx_id and order.state == 'manual',
'token': token,
}
if order.require_payment or (not tx_id and order.state == 'manual'):
@@ -85,7 +88,7 @@ class sale_quote(http.Controller):
attachments=sign and [('signature.png', sign.decode('base64'))] or []
order_obj.action_button_confirm(request.cr, SUPERUSER_ID, [order_id], context=request.context)
message = _('Order signed by %s') % (signer,)
self.__message_post(message, order_id, message_type='comment', subtype='mt_comment', attachments=attachments)
_message_post_helper(message=message, res_id=order_id, res_model='sale.order', attachments=attachments, **({'token': token, 'token_field': 'access_token'} if token else {}))
return True
@http.route(['/quote/<int:order_id>/<token>/decline'], type='http', auth="public", website=True)
@@ -97,37 +100,9 @@ class sale_quote(http.Controller):
request.registry.get('sale.order').action_cancel(request.cr, SUPERUSER_ID, [order_id])
message = post.get('decline_message')
if message:
self.__message_post(message, order_id, message_type='comment', subtype='mt_comment')
_message_post_helper(message=message, res_id=order_id, res_model='sale.order', **{'token': token, 'token_field': 'access_token'} if token else {})
return werkzeug.utils.redirect("/quote/%s/%s?message=2" % (order_id, token))
@http.route(['/quote/<int:order_id>/<token>/post'], type='http', auth="public", website=True)
def post(self, order_id, token, **post):
# use SUPERUSER_ID allow to access/view order for public user
order_obj = request.registry.get('sale.order')
order = order_obj.browse(request.cr, SUPERUSER_ID, order_id)
message = post.get('comment')
if token != order.access_token:
return request.website.render('website.404')
if message:
self.__message_post(message, order_id, message_type='comment', subtype='mt_comment')
return werkzeug.utils.redirect("/quote/%s/%s?message=1" % (order_id, token))
def __message_post(self, message, order_id, message_type='comment', subtype=False, attachments=[]):
request.session.body = message
cr, uid, context = request.cr, request.uid, request.context
user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
if 'body' in request.session and request.session.body:
request.registry.get('sale.order').message_post(cr, SUPERUSER_ID, order_id,
body=request.session.body,
message_type=message_type,
subtype=subtype,
author_id=user.partner_id.id,
context=context,
attachments=attachments
)
request.session.body = False
return True
@http.route(['/quote/update_line'], type='json', auth="public", website=True)
def update(self, line_id, remove=False, unlink=False, order_id=None, token=None, **post):
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, int(order_id))
@@ -351,32 +351,11 @@
<section id="discussion" class="hidden-print">
<h1 class="page-header">History</h1>
<!-- Options:Quotation Chatter: user can reply -->
<section class="mb32 css_editable_mode_hidden hidden-print">
<form id="comment" class="js_website_submit_form" t-attf-action="/quote/#{quotation.id}/#{quotation.access_token}/post" method="POST">
<img class="img pull-left img-rounded" t-att-src="website.image_url(user_id.partner_id, 'image_small')" style="width: 50px; margin-right: 10px;"/>
<div class="pull-left mb32" style="width: 75%%">
<textarea rows="4" name="comment" class="form-control" placeholder="Send us a note..."></textarea>
<button type="submit" class="btn btn-primary mt8">Send</button>
</div>
</form>
</section>
<div class="clearfix"/>
<!-- Options:Quotation Chatter: user can view history -->
<ul class="media-list" id="comments-list">
<t t-foreach="quotation.message_ids" t-as="message">
<li class="media" t-if="message.message_type not in ['comment', 'notification'] or message.subtype_id">
<div class="media-body">
<img class="media-object pull-left" t-att-src="website.image_url(message.author_id, 'image_small')" style="width: 50px; margin-right: 10px;"/>
<div class="media-body">
<h5 class="media-heading">
<span t-field="message.author_id"/> <small>on <span t-field="message.date"/></small>
</h5>
<div t-field="message.body"/>
</div>
</div>
</li>
</t>
</ul>
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="quotation"/>
<t t-set="token_field" t-value="'access_token'"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</section>
</xpath>
<xpath expr="//a[@data-target='#modaldecline']" position="before">
@@ -637,7 +616,7 @@
</xpath>
</template>
<template id="quotations" inherit_id="website_portal.quotations">
<template id="quotations" inherit_id="website_portal_sale.quotations">
<xpath expr="//t[@t-foreach='quotations']" position="replace">
<t t-foreach="quotations" t-as="quotation">
<tr t-att-class="'hidden to_hide' if quotation_index &gt; 4 else ''">