Skip to content
Permalink
Browse files

[IMP] sale: improve the code

  • Loading branch information...
mba-odoo committed Apr 15, 2019
1 parent b4af1cd commit 4dc4273fef57ffd171c43d06b4fad420a259c7e4
@@ -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>
@@ -21,24 +21,19 @@ def update(self, line_id, remove=False, unlink=False, order_id=None, access_toke
order_line = request.env['sale.order.line'].sudo().browse(int(line_id))
if order_line.order_id != order_sudo:
return False
values = {
'sale_order': order_sudo,
'report_type': "html"
}
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
quantity = order_line.product_uom_qty + number
order_line.write({'product_uom_qty': quantity})
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 +52,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,10 +1,9 @@
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',
@@ -30,19 +29,13 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
order_id: $input.data('order-id')
},
}).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();
});
},

/**
* @private
* @param {MouseEvent} ev
@@ -58,14 +51,11 @@ publicWidget.registry.SaleUpdateLineButton = publicWidget.Widget.extend({
option_id: parseInt($input.data('option-id'))
},
}).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();
});
},
});

});
@@ -30,7 +30,7 @@

<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">

0 comments on commit 4dc4273

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