[IMP] web_widget_one2many_product_picker_sale_stock: Adapt to work with product_picker

pull/2076/head
Alexandre D. Díaz 2021-11-10 12:52:56 +01:00
parent 2c35b756da
commit 7237e9a569
6 changed files with 104 additions and 115 deletions

View File

@ -1,44 +1,21 @@
// Copyright 2020 Tecnativa - Alexandre Díaz // Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker_sale_stock.One2ManyProductPickerRecord", function ( odoo.define(
require "web_widget_one2many_product_picker_sale_stock.One2ManyProductPickerRecord",
) { function(require) {
"use strict"; "use strict";
var One2ManyProductPickerRecord = require( var One2ManyProductPickerRecord = require("web_widget_one2many_product_picker.One2ManyProductPickerRecord");
"web_widget_one2many_product_picker.One2ManyProductPickerRecord");
One2ManyProductPickerRecord.include({ One2ManyProductPickerRecord.include({
/** /**
* @override * @override
*/ */
_getQWebContext: function () { _getQWebContext: function() {
var qweb_context = this._super.apply(this, arguments); var qweb_context = this._super.apply(this, arguments);
qweb_context.show_sale_stock = this.options.showSaleStock; qweb_context.show_sale_stock = this.options.showSaleStock;
return qweb_context; return qweb_context;
}, },
});
/** }
* @override );
*/
on_detach_callback: function () {
if (!_.isEmpty(this.widgets.front)) {
for (var index in this.widgets.front) {
var widget = this.widgets.front[index];
if (widget.template === 'sale_stock.qtyAtDate') {
widget.$el.popover("hide");
}
}
}
this._super.apply(this, arguments);
},
/**
* @override
*/
destroy: function () {
this.on_detach_callback();
this._super.apply(this, arguments);
},
});
});

View File

@ -1,18 +1,21 @@
// Copyright 2020 Tecnativa - Alexandre Díaz // Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker_sale_stock.One2ManyProductPickerRenderer", function (require) { odoo.define(
"use strict"; "web_widget_one2many_product_picker_sale_stock.One2ManyProductPickerRenderer",
function(require) {
"use strict";
var One2ManyProductPickerRenderer = require("web_widget_one2many_product_picker.One2ManyProductPickerRenderer"); var One2ManyProductPickerRenderer = require("web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
One2ManyProductPickerRenderer.include({ One2ManyProductPickerRenderer.include({
/** /**
* @override * @override
*/ */
_getRecordOptions: function (search_record) { _getRecordOptions: function() {
var options = this._super.apply(this, arguments); var options = this._super.apply(this, arguments);
options["showSaleStock"] = this.options.show_sale_stock; options.showSaleStock = this.options.show_sale_stock;
return options; return options;
}, },
}); });
}); }
);

View File

@ -1,6 +1,8 @@
// Copyright 2020 Tecnativa - Alexandre Díaz // Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", function (require) { odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", function(
require
) {
"use strict"; "use strict";
var AbstractView = require("web.AbstractView"); var AbstractView = require("web.AbstractView");
@ -13,17 +15,20 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
* @returns {Object} * @returns {Object}
*/ */
function _constructFakeFieldDef(params) { function _constructFakeFieldDef(params) {
return _.extend({ return _.extend(
change_default: false, {
company_dependent: false, change_default: false,
manual: false, company_dependent: false,
views: {}, manual: false,
searchable: true, views: {},
store: false, searchable: true,
readonly: true, store: false,
required: false, readonly: true,
sortable: false, required: false,
}, params); sortable: false,
},
params
);
} }
/** /**
@ -33,10 +38,12 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
/** /**
* @override * @override
*/ */
init: function (viewInfo, params) { init: function(viewInfo, params) {
if (viewInfo.model === 'sale.order') { if (viewInfo.model === "sale.order") {
var widget_name = $(viewInfo.arch).find("field[name='order_line']").attr("widget"); var $fields = $(viewInfo.arch)
if (widget_name === "one2many_product_picker") { .find("field[name='order_line']");
var has_product_picker = _.some($fields, function(elm) { return $(elm).attr("widget") === "one2many_product_picker"; });
if (has_product_picker) {
this._injectSaleStockFields(viewInfo); this._injectSaleStockFields(viewInfo);
} }
return this._super(viewInfo, params); return this._super(viewInfo, params);
@ -48,7 +55,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
* @private * @private
* @param {Object} viewInfo * @param {Object} viewInfo
*/ */
_injectSaleStockFields: function (viewInfo) { _injectSaleStockFields: function(viewInfo) {
var to_inject = { var to_inject = {
product_type: _constructFakeFieldDef({ product_type: _constructFakeFieldDef({
depends: ["product_id.type"], depends: ["product_id.type"],
@ -61,7 +68,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"customer_lead", "customer_lead",
"product_uom_qty", "product_uom_qty",
"order_id.warehouse_id", "order_id.warehouse_id",
"order_id.commitment_date" "order_id.commitment_date",
], ],
type: "float", type: "float",
}), }),
@ -71,7 +78,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"customer_lead", "customer_lead",
"product_uom_qty", "product_uom_qty",
"order_id.warehouse_id", "order_id.warehouse_id",
"order_id.commitment_date" "order_id.commitment_date",
], ],
type: "float", type: "float",
}), }),
@ -81,7 +88,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"customer_lead", "customer_lead",
"product_uom_qty", "product_uom_qty",
"order_id.warehouse_id", "order_id.warehouse_id",
"order_id.commitment_date" "order_id.commitment_date",
], ],
type: "float", type: "float",
}), }),
@ -91,7 +98,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"customer_lead", "customer_lead",
"product_uom_qty", "product_uom_qty",
"order_id.warehouse_id", "order_id.warehouse_id",
"order_id.commitment_date" "order_id.commitment_date",
], ],
type: "datetime", type: "datetime",
}), }),
@ -100,7 +107,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"product_id", "product_id",
"product_uom_qty", "product_uom_qty",
"qty_delivered", "qty_delivered",
"state" "state",
], ],
relation: "stock.warehouse", relation: "stock.warehouse",
type: "many2one", type: "many2one",
@ -111,7 +118,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"customer_lead", "customer_lead",
"product_uom_qty", "product_uom_qty",
"order_id.warehouse_id", "order_id.warehouse_id",
"order_id.commitment_date" "order_id.commitment_date",
], ],
group_operator: "sum", group_operator: "sum",
type: "float", type: "float",
@ -121,7 +128,7 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"product_id", "product_id",
"route_id", "route_id",
"order_id.warehouse_id", "order_id.warehouse_id",
"product_id.route_ids" "product_id.route_ids",
], ],
type: "boolean", type: "boolean",
}), }),
@ -130,30 +137,32 @@ odoo.define("web_widget_one2many_product_picker_sale_stock.AbstractView", functi
"product_id", "product_id",
"product_uom_qty", "product_uom_qty",
"qty_delivered", "qty_delivered",
"state" "state",
], ],
type: "boolean", type: "boolean",
}), }),
}; };
viewInfo.viewFields.order_line.views.form.fields = viewInfo.viewFields.order_line.views.form.fields = _.extend(
_.extend({}, to_inject, viewInfo.viewFields.order_line.views.form.fields); {},
to_inject,
viewInfo.viewFields.order_line.views.form.fields
);
// Add fields to arch // Add fields to arch
var field_names = Object.keys(to_inject); var field_names = Object.keys(to_inject);
var $arch = $(viewInfo.viewFields.order_line.views.form.arch); var $arch = $(viewInfo.viewFields.order_line.views.form.arch);
for (var index in field_names) { for (var index in field_names) {
var field_name = field_names[index]; var field_name = field_names[index];
var $field = $arch.find("field[name='"+field_name+"']"); var $field = $arch.find("field[name='" + field_name + "']");
if (!$field.length) { if (!$field.length) {
$("<FIELD/>", { $("<FIELD/>", {
name: field_name, name: field_name,
invisible: 1, invisible: 1,
modifiers: "{\"invisible\": true}", modifiers: '{"invisible": true}',
}).appendTo($arch); }).appendTo($arch);
} }
} }
viewInfo.viewFields.order_line.views.form.arch = $arch[0].outerHTML; viewInfo.viewFields.order_line.views.form.arch = $arch[0].outerHTML;
} },
}); });
}); });

View File

@ -1,20 +1,21 @@
// Copyright 2020 Tecnativa - Alexandre Díaz // Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker_sale_stock.FieldOne2ManyProductPicker", function ( odoo.define(
require "web_widget_one2many_product_picker_sale_stock.FieldOne2ManyProductPicker",
) { function(require) {
"use strict"; "use strict";
var FieldOne2ManyProductPicker = require("web_widget_one2many_product_picker.FieldOne2ManyProductPicker"); var FieldOne2ManyProductPicker = require("web_widget_one2many_product_picker.FieldOne2ManyProductPicker");
FieldOne2ManyProductPicker.include({ FieldOne2ManyProductPicker.include({
/** /**
* @override * @override
*/ */
_getDefaultOptions: function () { _getDefaultOptions: function() {
var defaults = this._super.apply(this, arguments); var defaults = this._super.apply(this, arguments);
defaults["show_sale_stock"] = true; defaults.show_sale_stock = false;
return defaults; return defaults;
}, },
}); });
}); }
);

View File

@ -21,20 +21,18 @@
.oe_flip_card_inner { .oe_flip_card_inner {
.stock_info { .stock_info {
top: 50%; top: 5px;
left: 5px; right: 8px;
transform: translateY(-50%);
> .o_widget { > .o_widget {
> div { > div {
background-color: white; background-color: white;
border-radius: 50%; border-radius: 50%;
width: 2.5em; width: 2em;
height: 2.5em; height: 2em;
.fa { .fa {
margin-top: -3px; font-size: 2.5em;
font-size: 3em;
} }
} }
} }

View File

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<template> <template>
<t t-extend="One2ManyProductPicker.FlipCard.Front">
<t t-extend="One2ManyProductPicker.FlipCard"> <t
<t t-jquery="div[t-attf-class*=oe_flip_card_front] t[t-if='state']" t-operation="append"> t-jquery="t[t-call='One2ManyProductPicker.ActionButton']"
<t t-if="show_sale_stock &amp;&amp; state.model === 'sale.order.line'"> t-operation="after"
<div class="position-absolute m-0 text-left stock_info"> >
<widget name="qty_at_date_widget" width="0.1"/> <t t-if="has_onchange &amp;&amp; state.model === 'sale.order.line'">
<div class="position-absolute m-0 stock_info">
<widget name="qty_at_date_widget" width="0.1" />
</div> </div>
</t> </t>
</t> </t>
</t> </t>
</template> </template>