@ -0,0 +1,49 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
One2Many Duplicate Records Widget |
|||
================================= |
|||
This module allows for Duplicating one2many records. |
|||
|
|||
Configuration |
|||
============= |
|||
Add the 'one2many_duplicate' as the widget of One2many field. |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
======= |
|||
Affero General Public License, v3.0 (AGPL v3). |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
* Developers: (V16) Megha K, |
|||
(V17) Jumana Haseen, |
|||
(V18) Aysha Shalin, |
|||
Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import wizard |
@ -0,0 +1,46 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
{ |
|||
'name': 'One2Many Duplicate Records Widget', |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Extra Tools', |
|||
'summary': """This widget is used for duplicating one2many records.""", |
|||
'description': """This is a widget for one2many fields, by using this |
|||
widget we can duplicate records in one2many fields.""", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': 'https://www.cybrosys.com', |
|||
'depends': ['base', 'web', 'sale'], |
|||
'assets': { |
|||
'web.assets_backend': [ |
|||
'/one2many_duplicate_record_widget/static/src/js/one2many_duplicate.js', |
|||
'/one2many_duplicate_record_widget/static/src/xml/one2many_duplicate_templates.xml', |
|||
'/one2many_duplicate_record_widget/static/src/css/InputBox.css', |
|||
], |
|||
}, |
|||
'images': ['static/description/banner.png'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,6 @@ |
|||
## Module <one2many_duplicate_record_widget> |
|||
|
|||
#### 19.02.2025 |
|||
#### Version 18.0.1.0.0 |
|||
##### ADD |
|||
- Initial commit for One2Many Duplicate Records Widget |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 757 KiB |
After Width: | Height: | Size: 95 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 146 KiB |
After Width: | Height: | Size: 83 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 121 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 153 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 8.2 KiB |
@ -0,0 +1,3 @@ |
|||
.copy_btn { |
|||
padding-bottom: 2%; |
|||
} |
@ -0,0 +1,98 @@ |
|||
/** @odoo-module */ |
|||
import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; |
|||
import { registry } from "@web/core/registry"; |
|||
import { ListRenderer } from "@web/views/list/list_renderer"; |
|||
import { useService } from "@web/core/utils/hooks"; |
|||
import { onMounted, onWillUpdateProps } from "@odoo/owl"; |
|||
|
|||
export class DuplicateListRenderer extends ListRenderer { |
|||
setup(){ |
|||
super.setup() |
|||
onMounted(()=>{ |
|||
let list = this.props.list |
|||
list.selection = list.records.filter((rec) => rec.selected) |
|||
list.selectDomain = (value) => { |
|||
list.isDomainSelected = value; |
|||
list.model.notify(); |
|||
} |
|||
}) |
|||
onWillUpdateProps((nextProps)=> { |
|||
let list = nextProps.list |
|||
list.selection = list.records.filter((rec) => rec.selected) |
|||
list.selectDomain = (value) => { |
|||
list.isDomainSelected = value; |
|||
list.model.notify(); |
|||
} |
|||
}) |
|||
} |
|||
get hasSelectors() { |
|||
// Add selector option in one2many field
|
|||
this.props.allowSelectors = true |
|||
return this.props.allowSelectors && !this.env.isSmall; |
|||
} |
|||
toggleSelection() { |
|||
const list = this.props.list; |
|||
if (!this.canSelectRecord) { |
|||
return; |
|||
} |
|||
if (list.selection.length === list.records.length) { |
|||
list.records.forEach((record) => { |
|||
record.toggleSelection(false); |
|||
list.selectDomain(false); |
|||
}); |
|||
} else { |
|||
list.records.forEach((record) => { |
|||
record.toggleSelection(true); |
|||
}); |
|||
} |
|||
} |
|||
/** Function that returns if selected any records **/ |
|||
get selectAll() { |
|||
const list = this.props.list; |
|||
const nbDisplayedRecords = list.records.length; |
|||
if (list.isDomainSelected) { |
|||
return true; |
|||
} |
|||
else { |
|||
return false |
|||
} |
|||
} |
|||
} |
|||
|
|||
export class DuplicateX2ManyField extends X2ManyField { |
|||
setup() { |
|||
super.setup(); |
|||
this.orm = useService("orm"); |
|||
X2ManyField.components = {ListRenderer: DuplicateListRenderer }; |
|||
} |
|||
get hasSelected(){ |
|||
return this.list.records.filter((rec) => rec.selected).length |
|||
} |
|||
async DuplicateRecord(ev){ |
|||
let selectedRecords = this.list.records.filter((rec) => rec.selected) |
|||
// Duplicating selected options
|
|||
var model = this.field.relation; |
|||
var records = this.list.records; |
|||
var resModel = this.props.record.resModel; |
|||
var field = this.props.name; |
|||
var relation_field = this.field.relation_field; |
|||
var selected_values = [] |
|||
for (var i = 0; i < records.length; i++) { |
|||
if (records[i].selected == true){ |
|||
selected_values.push(records[i].evalContext.id); |
|||
} |
|||
} |
|||
await this.orm.call('duplicate.record', 'action_duplicate_records',[{ |
|||
'values': selected_values, 'resModel': resModel, 'field': field, |
|||
'relation_field': relation_field, 'model': model}], |
|||
).then((result) =>{ |
|||
location.reload(); |
|||
}); |
|||
} |
|||
} |
|||
export const O2manyMultiDelete = { |
|||
...x2ManyField, |
|||
component: DuplicateX2ManyField, |
|||
}; |
|||
DuplicateX2ManyField.template = "one2many_duplicate_record_widget.One2manyDuplicate"; |
|||
registry.category("fields").add("one2many_duplicate", O2manyMultiDelete); |
@ -0,0 +1,18 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!--Template for widget --> |
|||
<templates id="template" xml:space="preserve"> |
|||
<t t-name="one2many_duplicate_record_widget.One2manyDuplicate" |
|||
t-inherit="web.X2ManyField" t-inherit-mode="primary" owl="1"> |
|||
<xpath expr="//div[hasclass('o_x2m_control_panel')]" position="before"> |
|||
<div class="copy_btn"> |
|||
<button t-if="hasSelected" class="btn btn-light" |
|||
t-on-click="DuplicateRecord"> |
|||
<span class="fa fa-copy"/> |
|||
</button> |
|||
<t t-if="props.readonly"> |
|||
<span class="oe_form_char_content"/> |
|||
</t> |
|||
</div> |
|||
</xpath> |
|||
</t> |
|||
</templates> |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import duplicate_record |
@ -0,0 +1,63 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import logging |
|||
from odoo import models, api |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class DuplicateRecord(models.TransientModel): |
|||
""" Created model to duplicate the record """ |
|||
_name = 'duplicate.record' |
|||
_description = 'Duplicate Records' |
|||
|
|||
@api.model |
|||
def action_duplicate_records(self, selected_values): |
|||
""" Duplicating the records. |
|||
params: dict selected_values: list of records of selected One2many fields. |
|||
""" |
|||
values = selected_values.get('values') |
|||
model = selected_values.get('model') |
|||
|
|||
_logger.info(f"Model: {model}, Values: {values}") |
|||
|
|||
if values and isinstance(values, (list, int)): |
|||
try: |
|||
record = self.env[model].browse(values) |
|||
if not record.exists(): |
|||
_logger.info( |
|||
"No valid records found for the provided values.") |
|||
return True |
|||
|
|||
for rec in record: |
|||
datas = list(rec.read()) # This reads the record data |
|||
for data in datas[0]: |
|||
is_tuple = isinstance(datas[0][data], tuple) |
|||
if is_tuple: |
|||
datas[0][data] = datas[0][data][0] |
|||
self.env[model].create(datas) |
|||
except Exception as e: |
|||
_logger.error(f"An error occurred: {e}") |
|||
else: |
|||
_logger.info( |
|||
"Invalid or missing 'values' or 'model'. Skipping execution.") |
|||
return True |