[ADD] : create portal user of so customere
[IMP] : create a token when quotation is send to customer bzr revid: aja@tinyerp.com-20131212115025-ljbwb7z1dscpfu5v
This commit is contained in:
parent
26c8697526
commit
42a58bdfe4
|
@ -17,44 +17,50 @@ class sale_quote(http.Controller):
|
|||
order_id = order_pool.search(request.cr, SUPERUSER_ID, [('access_token', '=', token)], context=request.context)
|
||||
return order_id
|
||||
|
||||
@website.route(['/quote/<token>'], type='http', auth="public")
|
||||
def view(self, token=None, **post):
|
||||
def _get_token(self, order_id):
|
||||
order_pool = request.registry.get('sale.order')
|
||||
access_token = order_pool.browse(request.cr, SUPERUSER_ID, order_id, context=request.context).access_token
|
||||
return access_token or order_id
|
||||
|
||||
@website.route(['/quote/<token>','/quote/<int:order_id>'], type='http', auth="public")
|
||||
def view(self, token=None, order_id=None, **post):
|
||||
values = {}
|
||||
order_pool = request.registry.get('sale.order')
|
||||
|
||||
quotation = order_pool.browse(request.cr, SUPERUSER_ID, self.get_quote(token))[0]
|
||||
if token:
|
||||
order_id = self.get_quote(token)[0]
|
||||
quotation = order_pool.browse(request.cr, SUPERUSER_ID, order_id)
|
||||
render_template = 'website_sale_quote.so_quotation'
|
||||
values.update({
|
||||
'quotation' : quotation,
|
||||
'total_mail' : len(order_pool.search(request.cr, request.uid,[('access_token','=',token),('message_ids.type', '=', 'email')], context=request.context)),
|
||||
'total_mail' : len(order_pool.search(request.cr, request.uid,[('id','=',order_id),('message_ids.type', '=', 'email')], context=request.context)),
|
||||
})
|
||||
return request.website.render(render_template, values)
|
||||
|
||||
@website.route(['/quote/<token>/accept'], type='http', auth="public")
|
||||
def accept(self, token=None , **post):
|
||||
@website.route(['/quote/<int:order_id>/accept'], type='http', auth="public")
|
||||
def accept(self, order_id=None, **post):
|
||||
values = {}
|
||||
quotation = request.registry.get('sale.order').write(request.cr, SUPERUSER_ID, self.get_quote(token), {'state': 'manual'})
|
||||
return request.redirect("/quote/%s" % token)
|
||||
quotation = request.registry.get('sale.order').write(request.cr, SUPERUSER_ID, [order_id], {'state': 'manual'})
|
||||
return request.redirect("/quote/%s" % self._get_token(order_id))
|
||||
|
||||
@website.route(['/quote/<token>/decline'], type='http', auth="public")
|
||||
def decline(self, token=None , **post):
|
||||
@website.route(['/quote/<int:order_id>/decline'], type='http', auth="public")
|
||||
def decline(self, order_id=None, **post):
|
||||
values = {}
|
||||
quotation = request.registry.get('sale.order').write(request.cr, SUPERUSER_ID, self.get_quote(token), {'state': 'cancel'})
|
||||
return request.redirect("/quote/%s" % token)
|
||||
quotation = request.registry.get('sale.order').write(request.cr, SUPERUSER_ID, [order_id], {'state': 'cancel'})
|
||||
return request.redirect("/quote/%s" % self._get_token(order_id))
|
||||
|
||||
@website.route(['/quote/<token>/post'], type='http', auth="public")
|
||||
def post(self, token=None, **post):
|
||||
@website.route(['/quote/<int:order_id>/post'], type='http', auth="public")
|
||||
def post(self, order_id=None, **post):
|
||||
values = {}
|
||||
if post.get('new_message'):
|
||||
request.session.body = post.get('new_message')
|
||||
if 'body' in request.session and request.session.body:
|
||||
request.registry.get('sale.order').message_post(request.cr, request.uid, self.get_quote(token),
|
||||
request.registry.get('sale.order').message_post(request.cr, request.uid, order_id,
|
||||
body=request.session.body,
|
||||
type='email',
|
||||
subtype='mt_comment',
|
||||
)
|
||||
request.session.body = False
|
||||
return request.redirect("/quote/%s" % token)
|
||||
return request.redirect("/quote/%s" % self._get_token(order_id))
|
||||
|
||||
@website.route(['/quote/update_line'], type='json', auth="public")
|
||||
def update(self, line_id=None, remove=False, unlink=False, order_id=None, **post):
|
||||
|
@ -65,7 +71,7 @@ class sale_quote(http.Controller):
|
|||
val = self._update_order_line(line_id=int(line_id), number=(remove and -1 or 1))
|
||||
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
|
||||
return [val , order.amount_total]
|
||||
|
||||
|
||||
def _update_order_line(self,line_id, number):
|
||||
order_line_obj = request.registry.get('sale.order.line')
|
||||
order_line_val = order_line_obj.read(request.cr, SUPERUSER_ID, [int(line_id)], [], context=request.context)[0]
|
||||
|
|
|
@ -35,7 +35,6 @@ class sale_order_line(osv.osv):
|
|||
if product:
|
||||
desc = self.pool.get('product.product').browse(cr, uid, product, context).website_description
|
||||
res.get('value').update({'website_description': desc})
|
||||
print res
|
||||
return res
|
||||
|
||||
class sale_order(osv.osv):
|
||||
|
@ -48,20 +47,38 @@ class sale_order(osv.osv):
|
|||
'is_template': fields.boolean('Is Template'),
|
||||
}
|
||||
|
||||
def new_quotation_token(self, cr, uid, record_id,context=None):
|
||||
def new_quotation_token(self, cr, uid, ids,context=None):
|
||||
db_uuid = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
quotation_token = hashlib.sha256('%s-%s-%s' % (time.time(), db_uuid, record_id)).hexdigest()
|
||||
return self.write(cr, uid, [record_id],{'access_token': quotation_token,'quote_url': self.get_signup_url(cr, uid, quotation_token, context)} )
|
||||
quotation_token = hashlib.sha256('%s-%s-%s' % (time.time(), db_uuid, ids[0])).hexdigest()
|
||||
return self.write(cr, uid, ids,{'access_token': quotation_token,'quote_url': self._get_signup_url(cr, uid, False,quotation_token, context)} )
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
template_id = vals.get('template_id', False)
|
||||
new_id = super(sale_order, self).create(cr, uid, vals, context=context)
|
||||
self.new_quotation_token(cr, uid, new_id,context)
|
||||
self.create_portal_user(cr, uid, new_id, context=context)
|
||||
self.write(cr, uid, [new_id],{'quote_url': self._get_signup_url(cr, uid, new_id, False, context)} )
|
||||
return new_id
|
||||
|
||||
def get_signup_url(self, cr, uid, token, context=None):
|
||||
def action_quotation_send(self, cr, uid, ids, context=None):
|
||||
res = super(sale_order, self).action_quotation_send(cr, uid, ids, context=context)
|
||||
self.new_quotation_token(cr, uid, ids,context)
|
||||
return res
|
||||
|
||||
def create_portal_user(self, cr, uid, order_id, context=None):
|
||||
portal_ids = self.pool.get('res.groups').search(cr, uid, [('is_portal', '=', True)])
|
||||
user_wizard_pool = self.pool.get('portal.wizard.user')
|
||||
order = self.browse(cr, uid, order_id, context=context)
|
||||
wizard_id = self.pool.get('portal.wizard').create(cr, uid,{'portal_id': portal_ids and portal_ids[0] or False})
|
||||
user_id = user_wizard_pool.create(cr, uid,{
|
||||
'wizard_id':wizard_id,
|
||||
'partner_id':order.partner_id.id,
|
||||
'email':order.partner_id.email,
|
||||
'in_portal':True} )
|
||||
return user_wizard_pool.action_apply(cr, uid, [user_id], context=context)
|
||||
|
||||
def _get_signup_url(self, cr, uid, order_id=False, token=False, context=None):
|
||||
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='http://localhost:8069', context=context)
|
||||
url = "%s/quote/%s" % (base_url ,token)
|
||||
url = "%s/quote/%s" % (base_url ,token and token or order_id)
|
||||
return url
|
||||
|
||||
def _get_sale_order_line(self, cr, uid,template_id, context=None):
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<openerp>
|
||||
<data>
|
||||
<!--Email template -->
|
||||
<record id="email_template_sale_quote" model="email.template">
|
||||
<field name="name">Sales Quotation - Send by Email (Quote)</field>
|
||||
<record id="sale.email_template_edi_sale" model="email.template">
|
||||
<field name="name">Sales Order - Send by Email</field>
|
||||
<field name="email_from">${object.user_id.email or ''}</field>
|
||||
<field name="subject">${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })</field>
|
||||
<field name="partner_to">${object.partner_invoice_id.id}</field>
|
||||
|
|
|
@ -157,7 +157,7 @@
|
|||
<div class="collapse navbar-collapse navbar-top-collapse">
|
||||
<ul class="nav navbar-nav" id="top_menu">
|
||||
<li>
|
||||
<a type="submit" t-if="quotation.state != 'manual' and quotation.state != 'cancel'" t-href="/quote/#{ quotation.access_token }/accept">
|
||||
<a type="submit" t-if="quotation.state != 'manual' and quotation.state != 'cancel'" t-href="/quote/#{ quotation.id }/accept">
|
||||
<span class="fa-stack">
|
||||
<i class="fa fa-circle fa-stack-2x" style="color:#5cb85c;"></i>
|
||||
<i class="fa fa-check fa-stack-1x fa-inverse fa-success"></i>
|
||||
|
@ -166,7 +166,7 @@
|
|||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a type="submit" t-if="quotation.state != 'cancel'" t-href="/quote/#{ quotation.access_token }/decline">
|
||||
<a type="submit" t-if="quotation.state != 'cancel'" t-href="/quote/#{ quotation.id }/decline">
|
||||
<span class="fa-stack">
|
||||
<i class="fa fa-circle fa-stack-2x" style="color:#d9534f;"></i>
|
||||
<i class="fa fa-times fa-stack-1x fa-inverse"></i>
|
||||
|
@ -217,9 +217,9 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<form id="post" accept-charset="UTF-8" method="POST" t-att-action="'/quote/%%s/post#post' %% quotation.access_token">
|
||||
<form id="post" accept-charset="UTF-8" method="POST" t-att-action="'/quote/%%s/post#post' %% quotation.id">
|
||||
<textarea rows="3" id="new_message" name="new_message" placeholder="Your Comment....." class="form-control span7"> </textarea>
|
||||
<button type="submit" t-att-id="quotation.access_token" class="btn btn-info">Post your Comment</button>
|
||||
<button type="submit" t-att-id="quotation.id" class="btn btn-info">Post your Comment</button>
|
||||
</form>
|
||||
</template>
|
||||
<template id="so_quotation" name="Product Quotation">
|
||||
|
@ -249,7 +249,7 @@
|
|||
</t>
|
||||
</template>
|
||||
<template id="product_recommendation">
|
||||
<!-- <div class="container mt32" t-if="product.recommended_products()">-->
|
||||
<div class="container mt32" t-if="quotation.recommended_products()">
|
||||
<h3>Customers who have bought this product also bought:</h3>
|
||||
<div class='row mt16' style="margin-left: 15px !important;">
|
||||
<t t-foreach="quotation.recommended_products()" t-as="product">
|
||||
|
@ -257,18 +257,11 @@
|
|||
<div class='mt16 text-center'>
|
||||
<a href="#" t-field="product.name"/>
|
||||
<span t-field="product.image_small" t-field-options='{"widget": "image", "class": "img-rounded"}'/>
|
||||
<!-- <h5>-->
|
||||
<!-- <a t-href="/shop/product/#{ slug(product) }/"-->
|
||||
<!-- style="display: block">-->
|
||||
<!-- <span t-field='product.name'-->
|
||||
<!-- style="display: block"/>-->
|
||||
<!-- </a>-->
|
||||
<!-- </h5>-->
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
<!-- </div>-->
|
||||
</div>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue