Skip to content

Commit

Permalink
[ADD]web_duplicate_context
Browse files Browse the repository at this point in the history
New module which adds a specific key to the context after duplicating a record
  • Loading branch information
GuillemCForgeFlow committed Oct 18, 2024
1 parent 0322c81 commit 149fb9c
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/web_duplicate_context/setup.py
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.
14 changes: 14 additions & 0 deletions web_duplicate_context/__manifest__.py
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,
}
1 change: 1 addition & 0 deletions web_duplicate_context/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guillem Casassas <[email protected]>
4 changes: 4 additions & 0 deletions web_duplicate_context/readme/DESCRIPTION.rst
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.
4 changes: 4 additions & 0 deletions web_duplicate_context/readme/USAGE.rst
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`.
37 changes: 37 additions & 0 deletions web_duplicate_context/static/src/js/basic_model.js
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,
});
});
},
});
});
15 changes: 15 additions & 0 deletions web_duplicate_context/templates/assets.xml
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>

0 comments on commit 149fb9c

Please sign in to comment.