forked from Techsystech/web
[IMP] web_widget_one2many_tree_line_duplicate: pre-commit stuff
parent
b0d1dd59b7
commit
5229e9910b
|
@ -0,0 +1 @@
|
||||||
|
../../../../web_widget_one2many_tree_line_duplicate
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
|
@ -1,25 +1,21 @@
|
||||||
/* Copyright 2021 Tecnativa - Alexandre Díaz
|
/* Copyright 2021 Tecnativa - Alexandre Díaz
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
||||||
|
|
||||||
odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(require) {
|
odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const BasicModel = require("web.BasicModel");
|
const BasicModel = require("web.BasicModel");
|
||||||
const rpc = require("web.rpc");
|
const rpc = require("web.rpc");
|
||||||
|
|
||||||
function dateToServer(date) {
|
function dateToServer(date) {
|
||||||
return date
|
return date.clone().utc().locale("en").format("YYYY-MM-DD HH:mm:ss");
|
||||||
.clone()
|
|
||||||
.utc()
|
|
||||||
.locale("en")
|
|
||||||
.format("YYYY-MM-DD HH:mm:ss");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicModel.include({
|
BasicModel.include({
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_applyChange: function(recordID, changes) {
|
_applyChange: function (recordID, changes) {
|
||||||
// The normal way is to have only one change with the 'CLONE' operation
|
// The normal way is to have only one change with the 'CLONE' operation
|
||||||
// but to ensure that "omitOnchange" is used we check that almost one change
|
// but to ensure that "omitOnchange" is used we check that almost one change
|
||||||
// is a 'CLONE' operation.
|
// is a 'CLONE' operation.
|
||||||
|
@ -40,7 +36,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_applyX2ManyChange: function(record, fieldName, command) {
|
_applyX2ManyChange: function (record, fieldName, command) {
|
||||||
if (command.operation === "CLONE") {
|
if (command.operation === "CLONE") {
|
||||||
// Return this._applyX2ManyChangeOmitOnchange.apply(this, arguments);
|
// Return this._applyX2ManyChangeOmitOnchange.apply(this, arguments);
|
||||||
return this._cloneX2Many.apply(this, arguments);
|
return this._cloneX2Many.apply(this, arguments);
|
||||||
|
@ -57,7 +53,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
_cloneX2Many: function(record, fieldName, command, options) {
|
_cloneX2Many: function (record, fieldName, command, options) {
|
||||||
const localID =
|
const localID =
|
||||||
(record._changes && record._changes[fieldName]) ||
|
(record._changes && record._changes[fieldName]) ||
|
||||||
record.data[fieldName];
|
record.data[fieldName];
|
||||||
|
@ -72,9 +68,9 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
const loaded_views = Object.keys(list.fieldsInfo);
|
const loaded_views = Object.keys(list.fieldsInfo);
|
||||||
const field_views = Object.keys(fieldInfo.views);
|
const field_views = Object.keys(fieldInfo.views);
|
||||||
const to_load_views = field_views.filter(
|
const to_load_views = field_views.filter(
|
||||||
value => !loaded_views.includes(value)
|
(value) => !loaded_views.includes(value)
|
||||||
);
|
);
|
||||||
_.each(to_load_views, name => {
|
_.each(to_load_views, (name) => {
|
||||||
this.addFieldsInfo(localID, {
|
this.addFieldsInfo(localID, {
|
||||||
fields: fieldInfo.views[name].fields,
|
fields: fieldInfo.views[name].fields,
|
||||||
fieldInfo: fieldInfo.views[name].fieldsInfo[name],
|
fieldInfo: fieldInfo.views[name].fieldsInfo[name],
|
||||||
|
@ -84,8 +80,8 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
// Only load fields available in the views. Otherwise we could get into
|
// Only load fields available in the views. Otherwise we could get into
|
||||||
// problems when some process try to get their states.
|
// problems when some process try to get their states.
|
||||||
var whitelisted_fields = [];
|
var whitelisted_fields = [];
|
||||||
_.each(_.allKeys(record_command.fieldsInfo), function(view) {
|
_.each(_.allKeys(record_command.fieldsInfo), function (view) {
|
||||||
_.each(_.allKeys(record_command.fieldsInfo[view]), function(field) {
|
_.each(_.allKeys(record_command.fieldsInfo[view]), function (field) {
|
||||||
if (!whitelisted_fields.includes(field)) {
|
if (!whitelisted_fields.includes(field)) {
|
||||||
whitelisted_fields.push(field);
|
whitelisted_fields.push(field);
|
||||||
}
|
}
|
||||||
|
@ -121,14 +117,14 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return read_data.then(result => {
|
return read_data.then((result) => {
|
||||||
const clone_values = _.defaults(
|
const clone_values = _.defaults(
|
||||||
{},
|
{},
|
||||||
this._getValuesToClone(record_command, params),
|
this._getValuesToClone(record_command, params),
|
||||||
_.pick(result, whitelisted_fields)
|
_.pick(result, whitelisted_fields)
|
||||||
);
|
);
|
||||||
return this._makeCloneRecord(list.model, params, clone_values)
|
return this._makeCloneRecord(list.model, params, clone_values)
|
||||||
.then(id => {
|
.then((id) => {
|
||||||
const ids = [id];
|
const ids = [id];
|
||||||
list._changes = list._changes || [];
|
list._changes = list._changes || [];
|
||||||
list._changes.push({
|
list._changes.push({
|
||||||
|
@ -148,7 +144,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
}
|
}
|
||||||
return ids;
|
return ids;
|
||||||
})
|
})
|
||||||
.then(ids => {
|
.then((ids) => {
|
||||||
this._readUngroupedList(list).then(() => {
|
this._readUngroupedList(list).then(() => {
|
||||||
const x2ManysDef = this._fetchX2ManysBatched(list);
|
const x2ManysDef = this._fetchX2ManysBatched(list);
|
||||||
const referencesDef = this._fetchReferencesBatched(list);
|
const referencesDef = this._fetchReferencesBatched(list);
|
||||||
|
@ -169,7 +165,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
_applyChangeOmitOnchange: function(recordID, changes, options) {
|
_applyChangeOmitOnchange: function (recordID, changes, options) {
|
||||||
var record = this.localData[recordID];
|
var record = this.localData[recordID];
|
||||||
var field = false;
|
var field = false;
|
||||||
var defs = [];
|
var defs = [];
|
||||||
|
@ -218,7 +214,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
* main viewType from the record
|
* main viewType from the record
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
_pseudoOnChange: function(record, viewType) {
|
_pseudoOnChange: function (record, viewType) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var onchangeSpec = this._buildOnchangeSpecs(record, viewType);
|
var onchangeSpec = this._buildOnchangeSpecs(record, viewType);
|
||||||
if (!onchangeSpec) {
|
if (!onchangeSpec) {
|
||||||
|
@ -238,7 +234,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
args: [idList, currentData, [], onchangeSpec],
|
args: [idList, currentData, [], onchangeSpec],
|
||||||
context: context,
|
context: context,
|
||||||
})
|
})
|
||||||
.then(function(result) {
|
.then(function (result) {
|
||||||
if (!record._changes) {
|
if (!record._changes) {
|
||||||
// If the _changes key does not exist anymore, it means that
|
// If the _changes key does not exist anymore, it means that
|
||||||
// it was removed by discarding the changes after the rpc
|
// it was removed by discarding the changes after the rpc
|
||||||
|
@ -254,16 +250,16 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
record._domains = _.extend(record._domains, result.domain);
|
record._domains = _.extend(record._domains, result.domain);
|
||||||
}
|
}
|
||||||
// We're only interested in relational fields
|
// We're only interested in relational fields
|
||||||
const values = _.pick(result.value, v => {
|
const values = _.pick(result.value, (v) => {
|
||||||
return typeof v === "object";
|
return typeof v === "object";
|
||||||
});
|
});
|
||||||
return self._applyOnChange(values, record).then(function() {
|
return self._applyOnChange(values, record).then(function () {
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_makeCloneRecord: function(modelName, params, values) {
|
_makeCloneRecord: function (modelName, params, values) {
|
||||||
const targetView = params.viewType;
|
const targetView = params.viewType;
|
||||||
let fields = params.fields;
|
let fields = params.fields;
|
||||||
const fieldsInfo = params.fieldsInfo;
|
const fieldsInfo = params.fieldsInfo;
|
||||||
|
@ -325,8 +321,8 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
this.applyDefaultValues(record.id, values, {fieldNames: fieldNames})
|
this.applyDefaultValues(record.id, values, {fieldNames: fieldNames})
|
||||||
// This will ensure we refresh the proper properties
|
// This will ensure we refresh the proper properties
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var def = new Promise(function(resolve, reject) {
|
var def = new Promise(function (resolve, reject) {
|
||||||
var always = function() {
|
var always = function () {
|
||||||
if (record._warning) {
|
if (record._warning) {
|
||||||
if (params.allowWarning) {
|
if (params.allowWarning) {
|
||||||
delete record._warning;
|
delete record._warning;
|
||||||
|
@ -365,7 +361,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
_getValuesToClone: function(line_state, params) {
|
_getValuesToClone: function (line_state, params) {
|
||||||
const values_to_clone = {};
|
const values_to_clone = {};
|
||||||
const line_data = line_state.data;
|
const line_data = line_state.data;
|
||||||
for (const field_name in line_data) {
|
for (const field_name in line_data) {
|
||||||
|
@ -387,13 +383,13 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
[
|
[
|
||||||
6,
|
6,
|
||||||
0,
|
0,
|
||||||
_.map(value.data || [], item => {
|
_.map(value.data || [], (item) => {
|
||||||
return item.data.id;
|
return item.data.id;
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
} else if (field_info.type === "one2many") {
|
} else if (field_info.type === "one2many") {
|
||||||
values_to_clone[field_name] = _.map(value.data || [], item => {
|
values_to_clone[field_name] = _.map(value.data || [], (item) => {
|
||||||
return [
|
return [
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
@ -412,7 +408,7 @@ odoo.define("web_widget_one2many_tree_line_duplicate.BasicModel", function(requi
|
||||||
return values_to_clone;
|
return values_to_clone;
|
||||||
},
|
},
|
||||||
|
|
||||||
_generateChanges: function(record) {
|
_generateChanges: function (record) {
|
||||||
let res = this._super.apply(this, arguments);
|
let res = this._super.apply(this, arguments);
|
||||||
if (!_.isEmpty(record.clone_data)) {
|
if (!_.isEmpty(record.clone_data)) {
|
||||||
// If a cloned record, ensure that all fields are written (and not only the view fields)
|
// If a cloned record, ensure that all fields are written (and not only the view fields)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
odoo.define(
|
odoo.define(
|
||||||
"web_widget_one2many_tree_line_duplicate.One2manyTreeLineDuplicate",
|
"web_widget_one2many_tree_line_duplicate.One2manyTreeLineDuplicate",
|
||||||
function(require) {
|
function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
@ -20,7 +20,7 @@ odoo.define(
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
init: function(parent) {
|
init: function (parent) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
let allow_clone =
|
let allow_clone =
|
||||||
parent.attrs &&
|
parent.attrs &&
|
||||||
|
@ -38,7 +38,7 @@ odoo.define(
|
||||||
* @private
|
* @private
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_renderHeader: function() {
|
_renderHeader: function () {
|
||||||
var $thead = this._super.apply(this, arguments);
|
var $thead = this._super.apply(this, arguments);
|
||||||
if (this.addCloneIcon) {
|
if (this.addCloneIcon) {
|
||||||
$thead
|
$thead
|
||||||
|
@ -52,7 +52,7 @@ odoo.define(
|
||||||
* @override
|
* @override
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_renderFooter: function() {
|
_renderFooter: function () {
|
||||||
const $footer = this._super.apply(this, arguments);
|
const $footer = this._super.apply(this, arguments);
|
||||||
if (this.addCloneIcon) {
|
if (this.addCloneIcon) {
|
||||||
$footer.find("tr").append($("<td>"));
|
$footer.find("tr").append($("<td>"));
|
||||||
|
@ -66,7 +66,7 @@ odoo.define(
|
||||||
* @private
|
* @private
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_renderRow: function(record, index) {
|
_renderRow: function (record, index) {
|
||||||
const $row = this._super.apply(this, arguments);
|
const $row = this._super.apply(this, arguments);
|
||||||
if (this.addCloneIcon) {
|
if (this.addCloneIcon) {
|
||||||
const $icon = $("<button>", {
|
const $icon = $("<button>", {
|
||||||
|
@ -84,7 +84,7 @@ odoo.define(
|
||||||
* @private
|
* @private
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_getNumberOfCols: function() {
|
_getNumberOfCols: function () {
|
||||||
var n = this._super();
|
var n = this._super();
|
||||||
if (this.addCloneIcon) {
|
if (this.addCloneIcon) {
|
||||||
n++;
|
n++;
|
||||||
|
@ -97,7 +97,7 @@ odoo.define(
|
||||||
*
|
*
|
||||||
* @param {MouseEvent} ev
|
* @param {MouseEvent} ev
|
||||||
*/
|
*/
|
||||||
_onCloneIconClick: function(ev) {
|
_onCloneIconClick: function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var $row = $(ev.target).closest("tr");
|
var $row = $(ev.target).closest("tr");
|
||||||
|
@ -121,7 +121,7 @@ odoo.define(
|
||||||
/**
|
/**
|
||||||
* @param {CustomEvent} ev
|
* @param {CustomEvent} ev
|
||||||
*/
|
*/
|
||||||
_onCloneRecord: function(ev) {
|
_onCloneRecord: function (ev) {
|
||||||
const data = ev.data || {};
|
const data = ev.data || {};
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
if (!this.cloningRecord && this.activeActions.create) {
|
if (!this.cloningRecord && this.activeActions.create) {
|
||||||
|
|
Loading…
Reference in New Issue