[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>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 < widget.data.qty_to_deliver and !widget.data.is_mto">
|
||||
<a tabindex="0" class="fa fa-info-circle text-danger"/>
|
||||
</t>
|
||||
@@ -13,30 +13,23 @@
|
||||
<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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user