-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New module which adds a specific key to the context after duplicating a record
- Loading branch information
1 parent
0322c81
commit 149fb9c
Showing
9 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../web_duplicate_context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Web Duplicate Context", | ||
"summary": "Adds a specific key to the context after duplicating a record", | ||
"version": "13.0.1.0.0", | ||
"depends": ["web"], | ||
"data": ["templates/assets.xml"], | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"maintainers": ["GuillemCForgeFlow"], | ||
"website": "https://github.com/OCA/web", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Guillem Casassas <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Adds a specific key to the context after duplicating a record. | ||
|
||
It can be useful to perform specific actions just after duplicating a record. Such as | ||
restrict the edition of a record to only when the record is duplicated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Technical module, to be inherited by other modules. It provides with the needed logic | ||
to perform specific actions just after duplicating a record. | ||
|
||
The key added to the context is `from_duplicate`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
odoo.define("web_duplicate_context.BasicModel", function(require) { | ||
"use strict"; | ||
|
||
var BasicModel = require("web.BasicModel"); | ||
|
||
BasicModel.include({ | ||
duplicateRecord: function(recordID) { | ||
var self = this; | ||
var record = this.localData[recordID]; | ||
// Start of the hook | ||
var context = this._getContext(record, { | ||
additionalContext: {from_duplicate: true}, | ||
}); | ||
// End of the hook | ||
return this._rpc({ | ||
model: record.model, | ||
method: "copy", | ||
args: [record.data.id], | ||
context: context, | ||
}).then(function(res_id) { | ||
var index = record.res_ids.indexOf(record.res_id); | ||
record.res_ids.splice(index + 1, 0, res_id); | ||
return self.load({ | ||
fieldsInfo: record.fieldsInfo, | ||
fields: record.fields, | ||
modelName: record.model, | ||
res_id: res_id, | ||
res_ids: record.res_ids.slice(0), | ||
viewType: record.viewType, | ||
context: context, | ||
}); | ||
}); | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<template | ||
id="assets_backend" | ||
name="web_duplicate_context assets" | ||
inherit_id="web.assets_backend" | ||
> | ||
<xpath expr="." position="inside"> | ||
<script | ||
type="text/javascript" | ||
src="/web_duplicate_context/static/src/js/basic_model.js" | ||
/> | ||
</xpath> | ||
</template> | ||
</odoo> |