[IMP] Misc Fixes

bzr revid: fp@tinyerp.com-20140125161203-zy29ixl0vgni8pxy
This commit is contained in:
Fabien Pinckaers 2014-01-25 17:12:03 +01:00
parent cbfd9a5540
commit b1f131c9c6
6 changed files with 30 additions and 49 deletions

View File

@ -84,7 +84,7 @@
<record id="menu_website" model="ir.ui.menu">
<field name="name">Website</field>
<field name="sequence" eval="11"/>
<field name="sequence" eval="400"/>
<field name="action" ref="action_website"/>
</record>
<record id="base.open_menu" model="ir.actions.todo">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -29,36 +29,26 @@ import datetime
from openerp.tools.translate import _
class sale_quote(http.Controller):
@http.route([
"/quote/<int:order_id>",
"/quote/<int:order_id>/<token>"
], type='http', auth="public", website=True)
def view(self, order_id, token=None, message=False, **post):
# use SUPERUSER_ID allow to access/view order for public user
# only if he knows the private token
order = request.registry.get('sale.order').browse(request.cr, token and SUPERUSER_ID or request.uid, order_id)
print order.name
if token:
assert token == order.access_token, 'Access denied!'
body=_('Quotation viewed by customer')
self.message_post(body, order_id, type='comment')
# TODO: if not order.template_id: return to the URL of the portal view of SO
self.__message_post(body, order_id, type='comment')
values = {
'quotation': order,
'message': message,
'new_post' : request.httprequest.session.get('new_post',False),
'option': self._check_option_len(order),
'date_diff': order.validity_date and (datetime.datetime.now() > datetime.datetime.strptime(order.validity_date , '%Y-%m-%d')) or False,
'salesperson' : False if token else True
'option': bool(filter(lambda x: not x.line_id, order.options)),
'order_valid': (not order.validity_date) or (datetime.datetime.now().strftime('%Y-%m-%d') <= order.validity_date),
}
return request.website.render('website_quotation.so_quotation', values)
def _check_option_len(self, order):
for option in order.options:
if not option.line_id:
return True
return False
@http.route(['/quote/accept'], type='json', auth="public", website=True)
def accept(self, order_id=None, token=None, signer=None, sign=None, **post):
order_obj = request.registry.get('sale.order')
@ -68,23 +58,22 @@ class sale_quote(http.Controller):
if not signer: error['signer'] = 'missing'
if not sign: error['sign'] = 'missing'
if not error:
attachment = {
'name': 'sign.png',
'datas':sign,
'datas_fname': 'sign.png',
'res_model': 'sale.order',
'res_id': order_id,
}
request.registry['ir.attachment'].create(request.cr, request.uid, attachment, context=request.context)
order_obj.write(request.cr, request.uid, [order_id], {'signer_name':signer,'state': 'manual'})
order_obj.signal_order_confirm(request.cr, SUPERUSER_ID, [order_id], context=request.context)
message = _('Order signed by %s') % (signer,)
self.__message_post(message, order_id, type='comment', subtype='mt_comment',
attachments=[('signature.png', sign)])
return [error]
@http.route(['/quote/<int:order_id>/<token>/decline'], type='http', auth="public", website=True)
def decline(self, order_id, token, **post):
order_obj = request.registry.get('sale.order')
order = order_obj.browse(request.cr, SUPERUSER_ID, order_id)
assert token == order.access_token, 'Access denied, wrong token!'
request.registry.get('sale.order').action_cancel(request.cr, SUPERUSER_ID, [order_id])
message = post.get('decline_message')
request.registry.get('sale.order').write(request.cr, request.uid, [order_id], {'state': 'cancel'})
if message:
self.message_post(message, order_id, type='comment', subtype='mt_comment')
self.__message_post(message, order_id, type='comment', subtype='mt_comment')
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)
@ -95,11 +84,10 @@ class sale_quote(http.Controller):
message = post.get('comment')
assert token == order.access_token, 'Access denied, wrong token!'
if message:
self.message_post(message, order_id, type='comment', subtype='mt_comment')
request.httprequest.session['new_post'] = True
self.__message_post(message, order_id, type='comment', subtype='mt_comment')
return werkzeug.utils.redirect("/quote/%s/%s?message=1" % (order_id, token))
def message_post(self , message, order_id, type='comment', subtype=False):
def __message_post(self, message, order_id, 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)
@ -110,6 +98,7 @@ class sale_quote(http.Controller):
subtype=subtype,
author_id=user.partner_id.id,
context=context,
attachments=attachments
)
request.session.body = False
return True
@ -121,23 +110,19 @@ class sale_quote(http.Controller):
if unlink:
request.registry.get('sale.order.line').unlink(request.cr, SUPERUSER_ID, [int(line_id)], context=request.context)
return False
val = self._update_order_line(line_id=int(line_id), number=(remove and -1 or 1))
return [str(val), str(order.amount_total)]
line_id=ine(line_id)
number=(remove and -1 or 1)
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, [line_id], [], context=request.context)[0]
quantity = order_line_val['product_uom_qty'] + number
order_line_obj.write(request.cr, SUPERUSER_ID, [line_id], {'product_uom_qty': (quantity)}, context=request.context)
return quantity
return [str(quantity), str(order.amount_total)]
@http.route(["/template/<model('sale.quote.template'):quote>"], type='http', auth="user", website=True)
def template_view(self, quote, **post):
values = {
'template': quote,
}
values = { 'template': quote }
return request.website.render('website_quotation.so_template', values)
@http.route(["/quote/add_line/<int:option_id>/<int:order_id>/<token>"], type='http', auth="public", website=True)
def add(self, option_id, order_id, token, **post):

View File

@ -100,7 +100,6 @@ class sale_order(osv.osv):
'template_id': fields.many2one('sale.quote.template', 'Quote Template'),
'website_description': fields.html('Description'),
'options' : fields.one2many('sale.order.option', 'order_id', 'Optional Products Lines'),
'signer_name': fields.char('Signer Name', size=256),
'validity_date': fields.date('Validity Date'),
'before_discount': fields.function(_get_total, string='Amount Before Discount', type="float")
}

View File

@ -40,7 +40,7 @@ $(document).ready(function () {
var sign = false;
var signer_name = false;
if($('#signature').length > 0){
var isSignature=$("#signature").jSignature('getData','base30')[1].length>1?true:false;
var isSignature=$("#signature").jSignature('getData','image')[1].length>1?true:false;
if (isSignature)
{
sign = JSON.stringify($("#signature").jSignature("getData",'image')[1]);

View File

@ -154,10 +154,10 @@
<div class="col-md-3">
<div class="bs-sidebar">
<div class="text-center hidden-print" t-if="quotation.state in ('draft', 'sent', 'waiting_date')" style="padding: 10px">
<a t-if="not date_diff" class="btn btn-primary btn-block fa fa-check" data-toggle="modal" data-target="#modelaccept">
<a t-if="order_valid" class="btn btn-primary btn-block fa fa-check" data-toggle="modal" data-target="#modelaccept">
Accept Order
</a>
<a t-if="date_diff">
<a t-if="not order_valid">
<strong>This offer expired!.</strong> <a href="#discussion">Contact us</a> for new quote.
</a>
<div class="mt8">
@ -172,7 +172,7 @@
<hr class="mt0 mb0"/>
<t t-call="website_quotation.navigation_menu"/>
<hr class="mt0 mb0"/>
<div t-if="not date_diff" class="text-center hidden-print">
<div t-if="order_valid" class="text-center hidden-print">
<input type="hidden" t-att-value="quotation.validity_date" id="validity_date"/>
<div class="mt8" t-if="(quotation.before_discount - quotation.amount_total) > 0.0">
<strong>This offer at </strong>
@ -224,7 +224,7 @@
<h4 class="modal-title">Validate Order</h4>
</div>
<div class="modal-body">
<p t-if="not salesperson">
<p>
I agree that by signing this proposal, I
accept it on the behalf of <b t-field="quotation.company_id"/>,
for an amount of
@ -232,12 +232,9 @@
t-field-options='{"widget": "monetary", "display_currency": "quotation.pricelist_id.currency_id"}'/>
with payment terms: <b t-field="quotation.payment_term"/>.
</p>
<p t-if="salesperson">
Only customer can validate this quotation.
</p>
</div>
<div class="modal-footer">
<button type="submit" t-attf-class="btn btn-primary #{salesperson and 'disabled' or ''}">Sign Order</button> or
<button type="submit" t-attf-class="btn btn-primary">Sign Order</button> or
<button type="button" class="btn btn-link" data-dismiss="modal" style="padding: 0">Cancel</button>
</div>
</form>
@ -359,11 +356,11 @@
<!-- Options:Quotation Signature -->
<template id="opt_quotation_signature" name="Signature" inherit_option_id="website_quotation.so_quotation" inherit_id="website_quotation.so_quotation">
<xpath expr="//div[@class='modal-body']" position="inside">
<div id="signer" class="form-group" t-if="not salesperson">
<div id="signer" class="form-group">
<label class="control-label" for="name">Your Name:</label>
<input type="text" name="signer" id="name" class="form-control"/>
</div>
<div class="panel panel-default mt16 mb0" id="drawsign" t-if="not salesperson">
<div class="panel panel-default mt16 mb0" id="drawsign">
<div class="panel-heading">
<div class="pull-right">
<a id="sign_clean" class="btn btn-xs">Clear</a>