summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2019-09-19 11:59:44 +0000
committerWilliam Henrotin <whe@odoo.com>2019-09-20 08:37:08 +0000
commit119167622761bf92a659fb3e0986ba82bbd1c158 (patch)
tree2d81e544ac95c867cb1ff4c171cc251eef3b6933
parent34791aa4032ea3da7591976257ebb7885fc469db (diff)
[FIX] sale_stock: quantity widget improvement
Commit fff2a30 introduced a popup on sale order line to show some information about available quantity of the sold product. This commit adds various imporvement on this widget closes odoo/odoo#36995 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
-rw-r--r--addons/sale_stock/models/sale_order.py7
-rw-r--r--addons/sale_stock/static/src/js/qty_at_date_widget.js12
-rw-r--r--addons/sale_stock/static/src/xml/qty_at_date.xml31
-rw-r--r--addons/sale_stock/views/sale_order_views.xml2
4 files changed, 28 insertions, 24 deletions
diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py
index 8e62094dea9..63fd29d4710 100644
--- a/addons/sale_stock/models/sale_order.py
+++ b/addons/sale_stock/models/sale_order.py
@@ -207,7 +207,7 @@ class SaleOrderLine(models.Model):
scheduled_date = fields.Datetime(compute='_compute_qty_at_date')
free_qty_today = fields.Float(compute='_compute_qty_at_date')
qty_available_today = fields.Float(compute='_compute_qty_at_date')
- warehouse_id = fields.Many2one(related='order_id.warehouse_id')
+ warehouse_id = fields.Many2one('stock.warehouse', compute='_compute_qty_at_date')
qty_to_deliver = fields.Float(compute='_compute_qty_to_deliver')
is_mto = fields.Boolean(compute='_compute_is_mto')
display_qty_widget = fields.Boolean(compute='_compute_qty_to_deliver')
@@ -236,13 +236,13 @@ class SaleOrderLine(models.Model):
for line in self:
if not line.display_qty_widget:
continue
- warehouse = line.order_id.warehouse_id
+ line.warehouse_id = line.order_id.warehouse_id
if line.order_id.commitment_date:
date = line.order_id.commitment_date
else:
confirm_date = line.order_id.date_order if line.order_id.state in ['sale', 'done'] else datetime.now()
date = confirm_date + timedelta(days=line.customer_lead or 0.0)
- grouped_lines[(warehouse.id, date)] |= line
+ grouped_lines[(line.warehouse_id.id, date)] |= line
treated = self.browse()
for (warehouse, scheduled_date), lines in grouped_lines.items():
@@ -268,6 +268,7 @@ class SaleOrderLine(models.Model):
remaining.scheduled_date = False
remaining.free_qty_today = False
remaining.qty_available_today = False
+ remaining.warehouse_id = False
@api.depends('product_id', 'route_id', 'order_id.warehouse_id', 'product_id.route_ids')
def _compute_is_mto(self):
diff --git a/addons/sale_stock/static/src/js/qty_at_date_widget.js b/addons/sale_stock/static/src/js/qty_at_date_widget.js
index db168822008..df3d60e8002 100644
--- a/addons/sale_stock/static/src/js/qty_at_date_widget.js
+++ b/addons/sale_stock/static/src/js/qty_at_date_widget.js
@@ -35,6 +35,16 @@ var QtyAtDateWidget = Widget.extend({
self._setPopOver();
});
},
+
+ updateState: function (state) {
+ this.$el.popover('dispose');
+ var candidate = state.data[this.getParent().currentRow];
+ if (candidate) {
+ this.data = candidate.data;
+ this.renderElement();
+ this._setPopOver();
+ }
+ },
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -58,7 +68,7 @@ var QtyAtDateWidget = Widget.extend({
var $forecastButton = $content.find('.action_open_forecast');
$forecastButton.on('click', function(ev) {
ev.stopPropagation();
- data_manager.load_action('stock.report_stock_quantity_action').then(function (action) {
+ data_manager.load_action('stock.report_stock_quantity_action_product').then(function (action) {
// Change action context to choose a specific date and product(s)
// As grid_anchor is set to now() by default in the data, we need
// to load the action first, change the context then launch it via do_action
diff --git a/addons/sale_stock/static/src/xml/qty_at_date.xml b/addons/sale_stock/static/src/xml/qty_at_date.xml
index beed0fe0325..be9e3bf7987 100644
--- a/addons/sale_stock/static/src/xml/qty_at_date.xml
+++ b/addons/sale_stock/static/src/xml/qty_at_date.xml
@@ -1,6 +1,6 @@
<templates>
<div t-name="sale_stock.qtyAtDate">
- <div t-att-class="!widget.data.product_id ? 'd-none' : ''">
+ <div t-att-class="!widget.data.display_qty_widget ? 'd-none' : ''">
<t t-if="widget.data.virtual_available_at_date &lt; widget.data.qty_to_deliver and !widget.data.is_mto">
<a tabindex="0" class="fa fa-info-circle text-danger"/>
</t>
@@ -13,31 +13,24 @@
<div t-name="sale_stock.QtyDetailPopOver">
<table>
<tbody>
- <tr>
- <td><strong>Expected Delivery</strong></td>
- <td class="oe-right"><span t-esc="data.delivery_date"/></td>
- </tr>
<t t-if="!data.is_mto">
<tr>
- <td><strong>Forecasted Stock</strong></td>
+ <td><strong>Forecasted Stock</strong><br /><small>On <span t-esc="data.delivery_date"/></small></td>
<td><t t-esc='data.virtual_available_at_date'/>
<t t-esc='data.product_uom.data.display_name'/></td>
</tr>
- <t t-if="data.debug">
- <tr>
- <td><strong>Stock On Hand</strong></td>
- <td><t t-esc='data.qty_available_today'/>
- <t t-esc='data.product_uom.data.display_name'/></td>
- </tr>
- <tr>
- <td><strong>Stock Available</strong><br /><small>On Hand - Reserved</small></td>
- <td><t t-esc='data.free_qty_today'/>
- <t t-esc='data.product_uom.data.display_name'/></td>
- </tr>
- </t>
+ <tr>
+ <td><strong>Available</strong><br /><small>All planned operations included</small></td>
+ <td><t t-esc='data.free_qty_today'/>
+ <t t-esc='data.product_uom.data.display_name'/></td>
+ </tr>
</t>
<t t-else="">
<tr>
+ <td><strong>Expected Delivery</strong></td>
+ <td class="oe-right"><span t-esc="data.delivery_date"/></td>
+ </tr>
+ <tr>
<p>This product is replenished on demand.</p>
</tr>
</t>
@@ -46,7 +39,7 @@
<button t-if="!data.is_mto" class="text-left btn btn-link action_open_forecast"
type="button">
<i class="fa fa-fw o_button_icon fa-arrow-right"></i>
- View Detailed Forecast
+ View Forecast
</button>
</div>
</templates>
diff --git a/addons/sale_stock/views/sale_order_views.xml b/addons/sale_stock/views/sale_order_views.xml
index d342368fb84..c07975c1415 100644
--- a/addons/sale_stock/views/sale_order_views.xml
+++ b/addons/sale_stock/views/sale_order_views.xml
@@ -92,7 +92,7 @@
<field name="qty_to_deliver" invisible="1"/>
<field name="is_mto" invisible="1"/>
<field name="display_qty_widget" invisible="1"/>
- <widget name="qty_at_date_widget" attrs="{'invisible': [('display_qty_widget', '=', False)]}"/>
+ <widget name="qty_at_date_widget" width="0.1"/>
</xpath>
</field>
</record>