Skip to content
Permalink
Browse files

[IMP] sale: improve the code

  • Loading branch information...
mba-odoo committed Apr 15, 2019
1 parent b4af1cd commit 3d9f7f0f2fd89eae8f899cfa7cccdd8d1f01fd6f
@@ -112,4 +112,5 @@ publicWidget.registry.SalePortalSidebar = PortalSidebar.extend({
return rawText.join(' ');
},
});
return publicWidget.registry.SalePortalSidebar;
});
@@ -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"/>
@@ -585,7 +584,6 @@
<span t-field="sale_order.payment_term_id"/>
</section>
</div>
</div>
</template>

</odoo>
@@ -23,22 +23,16 @@ def update(self, line_id, remove=False, unlink=False, order_id=None, access_toke
return False
if unlink:
order_line.unlink()
values = {
'sale_order': order_sudo,
'report_type': "html"
}
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", values)
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})
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_template", values)
return {
'quantity': str(quantity),
'amount': str(order_sudo.amount_total),
'price_subtotal': str(order_line.price_subtotal)
'sale_template': template
}

@http.route(["/my/orders/add_option"], type='json', auth="public", website=True)
@@ -57,8 +51,7 @@ def add(self, order_id, option_id, access_token=None, **post):
'sale_order': option_sudo.order_id,
'report_type': "html"
}
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_content", values)
template = request.env['ir.ui.view'].render_template("sale.sale_order_portal_template", values)
return {
'sale_order_portal_content': template,
'amount': option_sudo.order_id.amount_total
'sale_template': template,
}
@@ -1,71 +1,77 @@
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',
'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);
var params = {
line_id: parseInt($input.data('line-id')),
remove: $input.data('remove'),
unlink: $input.data('unlink'),
order_id: $input.data('order-id'),
};
var token = $input.data('token');
if (token) {
params['access_token'] = token;
}
this._rpc({
route: "/my/orders/update_line",
params: {
line_id: parseInt($input.data('line-id')),
remove: $input.data('remove'),
unlink: $input.data('unlink'),
order_id: $input.data('order-id')
},
params: params
}).then(function (data) {
if (!data['quantity']) {
self.$('.sale_order_portal').empty();
self.$('.sale_order_portal').append($(data['sale_order_portal_content']).children());
if ($('#optional_product').length){
self.$('.Options').show();
}
} else {
$input.closest('.input-group').find('.js_quantity').val(data['quantity']);
$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.$('#quote_content').replaceWith($template.find('#quote_content'));
self.$('#sidebar_content').replaceWith($template.find('#sidebar_content'));
self._generateMenu();
});
},

/**
* trigger when optional product added to order from portal.
*
* @private
* @param {MouseEvent} ev
*/
_onClickOptionalProduct: function (ev) {
ev.preventDefault();
var self = this;
var $input = $(ev.currentTarget);
var params = {
order_id: $input.data('order-id'),
option_id: parseInt($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: $input.data('order-id'),
option_id: parseInt($input.data('option-id'))
},
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.$('#quote_content').replaceWith($template.find('#quote_content'));
self.$('#sidebar_content').replaceWith($template.find('#sidebar_content'));
self._generateMenu();
$("html, body").animate({ scrollTop: self.$('#details').offset().top }, 100);
});
},
});

});
@@ -22,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 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">
@@ -66,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 role="button" 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>
@@ -84,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 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="mb8 js_update_line_json" aria-label="Remove one" title="Remove one">
<span class="fa fa-minus"/>
</a>
</span>
@@ -93,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 t-att-data-order-id="sale_order.id" t-att-data-token="sale_order.access_token" t-att-data-line-id="line.id" class="mb8 js_update_line_json" aria-label="Add one" title="Add one">
<span class="fa fa-plus"/>
</a>
</span>

0 comments on commit 3d9f7f0

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