mirror of https://github.com/OCA/web.git
[FIX] web_widget_one2many_product_picker_sale_secondary_unit: Secondary unit management
parent
4ba804cf70
commit
24cab7509d
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2021 Tecnativa - Alexandre Díaz
|
||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
odoo.define("web_widget_one2many_product_picker_sale_secondary_unit.One2ManyProductPickerRecord", function(
|
||||
require
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
const One2ManyProductPickerRecord = require("web_widget_one2many_product_picker.One2ManyProductPickerRecord");
|
||||
|
||||
One2ManyProductPickerRecord.include({
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_setMasterUomMap: function () {
|
||||
this._super.apply(this, arguments);
|
||||
if ((this.state && this.state.data && this.state.data.secondary_uom_id) ||
|
||||
!this.state && this.recordSearch && this.recordSearch.sale_secondary_uom_id) {
|
||||
_.extend(this.master_uom_map, {
|
||||
"field_uom": "secondary_uom",
|
||||
"field_uom_qty": "secondary_uom_qty",
|
||||
"search_field_uom": "sale_secondary_uom_id",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2021 Tecnativa - Alexandre Díaz
|
||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
odoo.define(
|
||||
"web_widget_one2many_product_picker_sale_secondary_unit.One2ManyProductPickerRenderer",
|
||||
function(require) {
|
||||
"use strict";
|
||||
|
||||
const One2ManyProductPickerRenderer = require("web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
|
||||
|
||||
One2ManyProductPickerRenderer.include({
|
||||
_isEqualState: function(state_a, state_b) {
|
||||
const res = this._super.apply(this, arguments);
|
||||
const secondary_uom_id_a =
|
||||
state_a.data.secondary_uom_id && state_a.data.secondary_uom_id.data.id;
|
||||
const secondary_uom_id_b =
|
||||
state_b.data.secondary_uom_id && state_b.data.secondary_uom_id.data.id;
|
||||
return res && secondary_uom_id_a === secondary_uom_id_b;
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2021 Tecnativa - Alexandre Díaz
|
||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
odoo.define("web_widget_one2many_product_picker_sale_secondary_unit.FieldOne2ManyProductPicker", function(
|
||||
require
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
const FieldOne2ManyProductPicker = require("web_widget_one2many_product_picker.FieldOne2ManyProductPicker");
|
||||
|
||||
FieldOne2ManyProductPicker.include({
|
||||
// Model product.product fields
|
||||
search_read_fields: _.unique([].concat(FieldOne2ManyProductPicker.prototype.search_read_fields, [
|
||||
"sale_secondary_uom_id",
|
||||
])),
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
_getDefaultOptions: function() {
|
||||
const res = this._super.apply(this, arguments);
|
||||
res.field_map.secondary_uom = "secondary_uom_id";
|
||||
res.field_map.secondary_uom_qty = "secondary_uom_qty";
|
||||
return res;
|
||||
},
|
||||
});
|
||||
});
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<template>
|
||||
<t t-extend="One2ManyProductPicker.FlipCard">
|
||||
|
||||
<t t-extend="One2ManyProductPicker.FlipCard.Front">
|
||||
<t
|
||||
t-jquery="t[t-if='state'] > t[t-elif='!is_virtual'] > div:first-child > span:first-child"
|
||||
t-jquery="t[t-call='One2ManyProductPicker.ActionButton']"
|
||||
t-operation="after"
|
||||
>
|
||||
<t
|
||||
t-if="state.model === 'sale.order.line' && state.data['secondary_uom_id']"
|
||||
t-if="state.model === 'sale.order.line' && state.data['secondary_uom_id'] && (!is_virtual || modified)"
|
||||
>
|
||||
<span
|
||||
data-field="secondary_uom_qty"
|
||||
data-esc="str(secondary_uom_qty) + ' x ' + secondary_uom_id.data.display_name"
|
||||
class="badge badge-primary font-weight-bold rounded-0 mt-1 p-2"
|
||||
t-att-data-field="field_map[field_uom_qty]"
|
||||
t-attf-data-esc="str({{field_map.product_uom_qty}}) + ' x ' + {{field_map.product_uom}}.data.display_name"
|
||||
class="badge badge-primary mw-100 text-truncate overflow-hidden d-inline-block float-left font-weight-bold rounded-0 m-0 p-2"
|
||||
/>
|
||||
</t>
|
||||
</t>
|
||||
|
|
|
@ -6,6 +6,18 @@
|
|||
inherit_id="web_widget_one2many_product_picker.assets_backend"
|
||||
>
|
||||
<xpath expr="." position="inside">
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/widgets/field_one2many_product_picker.js"
|
||||
/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/One2ManyProductPicker/record.js"
|
||||
/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/One2ManyProductPicker/renderer.js"
|
||||
/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/abstract_view.js"
|
||||
|
|
Loading…
Reference in New Issue