Skip to content
Permalink
Browse files

[IMP] sale: code improvement

  • Loading branch information...
pla-odoo authored and mba-odoo committed Apr 10, 2019
1 parent 19a7630 commit 5123eb63e9d91a38db96511d91d975b7277ea81e
@@ -84,7 +84,7 @@ publicWidget.registry.SalePortalSidebar = PortalSidebar.extend({
if (!lastUL) {
lastUL = $("<ul class='nav flex-column'>").appendTo(lastLI);
}
$("<li class='nav-item'>").append($('<a class="nav-link ' + text + '" href="#' + id + '"/>').text(text)).appendTo(lastUL);
$("<li class='nav-item'>").append($('<a class="nav-link" href="#' + id + '"/>').text(text)).appendTo(lastUL);
}
break;
}
@@ -112,4 +112,5 @@ publicWidget.registry.SalePortalSidebar = PortalSidebar.extend({
return rawText.join(' ');
},
});
return publicWidget.registry.SalePortalSidebar;
});
@@ -127,7 +127,7 @@
<t t-set="classes" t-value="'col-12 col-lg flex-lg-grow-0 d-print-none'"/>

<t t-set="title">
<h2 class="mb-0"><b><span data-id="total_amount" t-field="sale_order.amount_total"></span></b></h2>
<h2 class="mb-0"><b class="o_portal_sale_total_amount" t-field="sale_order.amount_total"/> </h2>
</t>
<t t-set="entries">
<ul class="list-group list-group-flush flex-wrap flex-row flex-lg-column">
@@ -149,7 +149,7 @@
</li>

<li class="navspy list-group-item pl-0 flex-grow-1" t-ignore="true" role="complementary">
<ul class="nav flex-column bs-sidenav"></ul>
<ul class="nav flex-column bs-sidenav" id="o_portal_sale_sidebar_nav"></ul>
</li>

<t t-if="not sale_order.is_expired and sale_order.state in ['draft', 'sent']">
@@ -170,11 +170,11 @@
class="d-block mt-1"/>
</small>
<t t-if="sale_order.amount_untaxed == sale_order.amount_total">
<h4 t-field="sale_order.amount_total" class="text-success"/>
<h4 t-field="sale_order.amount_total" class="o_portal_sale_total_amount text-success"/>
</t>
<t t-else="">
<h4 t-field="sale_order.amount_untaxed" class="text-success mb-0"/>
<small>(<span t-field="sale_order.amount_total"/> Incl. tax)</small>
<small>(<span class="o_portal_sale_total_amount" t-field="sale_order.amount_total"/> Incl. tax)</small>
</t>
</li>
</t>
@@ -213,7 +213,7 @@
<span>By signing this proposal, I agree to the following terms:</span>
<ul>
<li><span>Accepted on the behalf of:</span> <b t-field="sale_order.partner_id.commercial_partner_id"/></li>
<li><span>For an amount of:</span> <b data-id="total_amount" t-field="sale_order.amount_total"/></li>
<li><span>For an amount of:</span> <b class="o_portal_sale_total_amount" data-id="total_amount" t-field="sale_order.amount_total"/></li>
<li t-if="sale_order.payment_term_id"><span>With payment terms:</span> <b t-field="sale_order.payment_term_id"/></li>
</ul>
</p>
@@ -236,7 +236,7 @@
<span>By paying this proposal, I agree to the following terms:</span>
<ul>
<li><span>Accepted on the behalf of:</span> <b t-field="sale_order.partner_id.commercial_partner_id"/></li>
<li><span>For an amount of:</span> <b data-id="total_amount" t-field="sale_order.amount_total"/></li>
<li><span>For an amount of:</span> <b class="o_portal_sale_total_amount" data-id="total_amount" t-field="sale_order.amount_total"/></li>
<li t-if="sale_order.payment_term_id"><span>With payment terms:</span> <b t-field="sale_order.payment_term_id"/></li>
</ul>
</p>
@@ -311,7 +311,7 @@
</div>

<!-- main content -->
<div t-attf-class="card #{'pb-5' if report_type == 'html' else ''}">
<div t-attf-class="card #{'pb-5' if report_type == 'html' else ''}" id="portal_sale_content">
<div t-call="sale.sale_order_portal_content"/>
</div>

@@ -355,7 +355,6 @@
-->
<template id="sale_order_portal_content" name="Sales Order Portal Content">
<!-- Intro -->
<div class="sale_order_portal p-4">
<div id="introduction" t-attf-class="pb-2 pt-3 #{'card-header bg-white' if report_type == 'html' else ''}">
<h2 class="my-0">
<t t-esc="sale_order.type_name"/>
@@ -483,7 +482,7 @@
<span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_id))"/>
</td>
<td class="text-right">
<span data-id="price_subtotal" t-field="line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<span t-field="line.price_subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
<span t-field="line.price_total" groups="account.group_show_line_subtotals_tax_included"/>
</td>
</t>
@@ -585,7 +584,6 @@
<span t-field="sale_order.payment_term_id"/>
</section>
</div>
</div>
</template>

</odoo>
@@ -9,7 +9,7 @@

class CustomerPortal(CustomerPortal):

@http.route(['/my/orders/<int:order_id>/update_line'], type='json', auth="public", website=True)
@http.route(['/my/orders/update_line'], type='json', auth="public", website=True)
def update(self, line_id, remove=False, unlink=False, order_id=None, access_token=None, **post):
try:
order_sudo = self._document_check_access('sale.order', order_id, access_token=access_token)
@@ -23,19 +23,18 @@ def update(self, line_id, remove=False, unlink=False, order_id=None, access_toke
return False
if unlink:
order_line.unlink()
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", {
'sale_order': order_sudo, 'report_type': "html",
})
return {'amount': str(order_sudo.amount_total), 'sale_order_portal_content': template}
number = 0 if order_line.product_uom_qty == 1 and remove else -1 if remove else 1
quantity = order_line.product_uom_qty + number
order_line.write({'product_uom_qty': quantity})
value = {
'quantity': str(quantity),
'amount': str(order_sudo.amount_total),
'price_subtotal': str(order_line.price_subtotal)
}
return value
else:
number = 0 if order_line.product_uom_qty == 1 and remove else -1 if remove else 1
order_line.write({'product_uom_qty': order_line.product_uom_qty + number})
values = {
'sale_order': order_sudo,
'report_type': "html"
}
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", values)
return {
'sale_template': template,
'total_amount': order_sudo.amount_total,
}

@http.route(["/my/orders/add_option"], type='json', auth="public", website=True)
def add(self, order_id, option_id, access_token=None, **post):
@@ -49,9 +48,12 @@ def add(self, order_id, option_id, access_token=None, **post):
if order_sudo != option_sudo.order_id:
return False
option_sudo.add_option_to_order()
value = {}
value['sale_order_portal_content'] = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", {
'sale_order': option_sudo.order_id, 'report_type': "html",
})
value['amount'] = option_sudo.order_id.amount_total
return value
values = {
'sale_order': option_sudo.order_id,
'report_type': "html"
}
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", values)
return {
'sale_template': template,
'total_amount': order_sudo.amount_total,
}
@@ -1,85 +1,79 @@
odoo.define('sale_management.sale_management', function (require) {
'use strict';

var publicWidget = require('web.public.widget');
var SalePortalSidebar = require('sale.SalePortalSidebar');

publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
selector: '.o_portal_sale_sidebar',
SalePortalSidebar.include({
events: {
'click a.js_update_line_json': '_onClick',
'click a.js_add_optional_products': '_onClickOptionalProduct'
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* trigger when update the quantity of optional products.
*
* @private
* @param {Event} ev
*/
_onClick: function (ev) {
ev.preventDefault();
var self = this;
var $input = $(ev.currentTarget);
this.$input = $input;
var orderID = $input.data('order-id');
var lineID = $input.data('line-id');
var params = {
'line_id': parseInt(lineID),
'remove': $input.data('remove'),
'unlink': $input.data('unlink'),
line_id: parseInt($input.data('line-id')),
remove: $input.data('remove'),
unlink: $input.data('unlink'),
order_id: $input.data('order-id'),
};
var url = "/my/orders/" + parseInt(orderID) + "/update_line";
var token = $input.data('token');
if (token) {
params['access_token'] = token;
}
this._rpc({
route: url,
params: params,
route: "/my/orders/update_line",
params: params
}).then(function (data) {
if (!data['quantity']) {
self.$el.find('.sale_order_portal').empty();
self.$el.find('.sale_order_portal').append($(data['sale_order_portal_content']).children());
if ($('#optional_product').length){
self.$('.Options').show();
}
}
else {
self.$input.closest('.input-group').find('.js_quantity').val(data['quantity']);
self.$input.closest('tr').find($('[data-id="price_subtotal"] > span')).html(data['price_subtotal']);
}
$('[data-id="total_amount"] > span').html(data['amount']);
var $template = $(data['sale_template']);
self.$('#portal_sale_content').empty();
self.$('#portal_sale_content').append($template);
self.$('.o_portal_sale_total_amount span').text(data['total_amount']);
self.$('#o_portal_sale_sidebar_nav').empty();
self._generateMenu();
});
},
});

publicWidget.registry.SaleAddOptionalProduct = publicWidget.Widget.extend({
selector: '.o_portal_sale_sidebar .sale_order_portal',
events: {
'click a.js_add_optional_products': '_onClickOptionalProduct',
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* trigger when optional product added to order from portal.
*
* @private
*/
* @param {Event} ev
*/
_onClickOptionalProduct: function (ev) {
ev.preventDefault();
var self = this;
var $input = $(ev.currentTarget);
var orderID = $input.data('order-id');
var optionIDs = parseInt($input.data('option-id'));
var params = {
order_id: $input.data('order-id'),
option_id: $input.data('option-id'),
};
var token = $input.data('token');
if (token) {
params['access_token'] = token;
}
this._rpc({
route: "/my/orders/add_option",
params: {
order_id: orderID,
option_id: optionIDs
},
params: params
}).then(function (data) {
self.$el.empty();
self.$el.append($(data['sale_order_portal_content']).children());
if (!$('#optional_product').length){
$('.bs-sidenav').find('.Options').hide();
}
$('[data-id="total_amount"] > span').html(data['amount']);
var $template = $(data['sale_template']);
self.$('#portal_sale_content').empty();
self.$('#portal_sale_content').append($template);
self.$('.o_portal_sale_total_amount span').text(data['total_amount']);
self.$('#o_portal_sale_sidebar_nav').empty();
self._generateMenu();
});
},
});
@@ -14,7 +14,6 @@
</xpath>

<xpath expr="//section[@id='details']//table[@id='sales_order_table']/thead/tr" position="inside">
<t t-set="colspan" t-value="99"/>
<th t-if="display_remove">
<!-- TODO: remove in master -->
<t t-set="colspan" t-value="colspan+1"/>
@@ -23,15 +22,15 @@

<xpath expr="//section[@id='details']//t[@t-if='not line.display_type']" position="inside">
<td class="text-center" t-if="display_remove">
<a t-att-data-order-id="sale_order.id" t-att-data-unlink='1' t-att-data-line-id="line.id" class="mb8 js_update_line_json d-print-none" t-if="line.sale_order_option_ids" aria-label="Remove" title="Remove">
<a href="#" t-att-data-order-id="sale_order.id" t-att-data-unlink='1' t-att-data-token="sale_order.access_token" t-att-data-line-id="line.id" class="mb8 js_update_line_json d-print-none" t-if="line.sale_order_option_ids" aria-label="Remove" title="Remove">
<span class="fa fa-trash-o"></span>
</a>
</td>
</xpath>

<xpath expr="//section[@id='signature']" position="after">
<t t-if="any([(not option.line_id) for option in sale_order.sale_order_option_ids])">
<section id="optional_product">
<section>
<h3>Options</h3>
<t t-set="display_discount" t-value="True in [option.discount > 0 for option in sale_order.sale_order_option_ids]"/>
<table class="table table-sm">
@@ -67,7 +66,7 @@
</strong>
</td>
<td class="text-center" t-if="sale_order.state in ['draft', 'sent'] and report_type == 'html'">
<a role="button" class="mb8 pt0 btn btn-link js_add_optional_products" t-att-data-option-id="option.id" t-att-data-order-id="sale_order.id" aria-label="Add to cart" title="Add to cart">
<a href="#" class="mb8 pt0 btn btn-link js_add_optional_products" t-att-data-option-id="option.id" t-att-data-token="sale_order.access_token" t-att-data-order-id="sale_order.id" aria-label="Add to cart" title="Add to cart">
<span class="fa fa-shopping-cart"/>
</a>
</td>
@@ -85,7 +84,7 @@

<div class="input-group-prepend d-print-none">
<span class="input-group-text">
<a t-att-data-order-id="sale_order.id" t-att-data-remove='1' t-att-data-line-id="line.id" class="mb8 js_update_line_json" aria-label="Remove one" title="Remove one">
<a href="#" t-att-data-order-id="sale_order.id" t-att-data-remove='1' t-att-data-line-id="line.id" t-att-data-token="sale_order.access_token" class="js_update_line_json" aria-label="Remove one" title="Remove one">
<span class="fa fa-minus"/>
</a>
</span>
@@ -94,7 +93,7 @@
<input type="text" class="js_quantity form-control" t-att-data-id="line.id" t-att-value="line.product_uom_qty"/>
<div class="input-group-append d-print-none">
<span class="input-group-text">
<a t-att-data-order-id="sale_order.id" t-att-data-line-id="line.id" class="mb8 js_update_line_json" aria-label="Add one" title="Add one">
<a href="#" t-att-data-order-id="sale_order.id" t-att-data-token="sale_order.access_token" t-att-data-line-id="line.id" class="js_update_line_json" aria-label="Add one" title="Add one">
<span class="fa fa-plus"/>
</a>
</span>

0 comments on commit 5123eb6

Please sign in to comment.
You can’t perform that action at this time.