From ffd396b241e7e7e24b122e430d628bb60a7f883f Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Wed, 13 Sep 2023 16:34:03 +0530 Subject: [PATCH] Sep 13 [FIX] : Bug Fixed 'listview_change_background_color' --- .../doc/RELEASE_NOTES.md | 2 +- .../models/color_picker.py | 3 +- .../static/src/js/color_picker.js | 91 ++++++++++--------- .../static/src/xml/color_picker.xml | 20 ++-- 4 files changed, 62 insertions(+), 54 deletions(-) diff --git a/listview_change_background_color/doc/RELEASE_NOTES.md b/listview_change_background_color/doc/RELEASE_NOTES.md index efb84f288..93246ffa8 100644 --- a/listview_change_background_color/doc/RELEASE_NOTES.md +++ b/listview_change_background_color/doc/RELEASE_NOTES.md @@ -1,6 +1,6 @@ ## Module -#### 15.02.2022 +#### 31.08.2023 #### Version 16.0.1.0.0 #### ADD - Initial commit for Listview Change Background Color diff --git a/listview_change_background_color/models/color_picker.py b/listview_change_background_color/models/color_picker.py index 56093a2c8..c39c37af9 100644 --- a/listview_change_background_color/models/color_picker.py +++ b/listview_change_background_color/models/color_picker.py @@ -34,7 +34,8 @@ class ColorPicker(models.Model): @api.model def get_color_picker_model_and_id(self, **kw): """We can get the all records, models and colors""" - record = self.search([('record_id', '=', kw['record_id']), ('res_model', '=', kw['model_name'])]) + record = self.search([('record_id', '=', kw['record_id']), + ('res_model', '=', kw['model_name'])]) if record: record.write({'color': kw['record_color']}) else: diff --git a/listview_change_background_color/static/src/js/color_picker.js b/listview_change_background_color/static/src/js/color_picker.js index 4b3296e61..c09aa9d31 100644 --- a/listview_change_background_color/static/src/js/color_picker.js +++ b/listview_change_background_color/static/src/js/color_picker.js @@ -1,76 +1,77 @@ /** @odoo-module **/ - import { patch } from "@web/core/utils/patch"; import { ListRenderer } from "@web/views/list/list_renderer"; import { ListController } from '@web/views/list/list_controller'; - //For ORM Call import { useService } from "@web/core/utils/hooks"; - - -const { useRef, onPatched, onMounted, useState } = owl; - +const { useRef, onPatched, onMounted, useState,onWillUpdateProps } = owl; //Patching patch(ListRenderer.prototype, 'list-color-patch', { setup() { + if (this.constructor.name == 'SectionAndNoteListRenderer') { + // Call method for removing color picking field from one2many + onMounted(() => { + this.__owl__.bdom.el.children[0].children[1].childNodes.forEach((item) => { + if (item.nodeName != "#text"){ + if(!item.attributes.length == 0){ + var list_one2many = item.children[1]; + list_one2many.remove(); + } + } + }) + }) + } this._super.apply(); this.orm = useService("orm"); -// PATH OF CORRESPONDING MODEL -// var current_model = this.props.list.model.env.searchModel.resModel - onMounted(this.color) + onMounted(this.color); + if (this.constructor.name == 'SectionAndNoteListRenderer') { + // Call method for removing color picking field from one2many + onPatched(()=>{ + this.__owl__.bdom.el.children[0].children[1].childNodes.forEach((item) => { + if (item.nodeName != "#text"){ + if(!item.attributes.length == 0){ + var list_one2many = item.children[1]; + list_one2many.remove(); + } + } + }) + }); + } + onPatched(()=>{ + this.color() + }); }, - - color_pick(ev,record){ var color = ev.target.value var res_id = record.resId var res_model = record.resModel - - //ORM Call - + //ORM Call this.orm.call("color.picker","get_color_picker_model_and_id",[],{ record_id: res_id, model_name: res_model, record_color: color, }).then(function(data){ - - }) - - ev.target.parentNode.parentNode.style.backgroundColor = color }, - - -//Call from onMounted + //Call from onMounted color(){ - var current_model = this.props.list.model.env.searchModel.resModel - var tr_list = $('.o_data_row') - var current_tr; - - + var current_model = this.props.list.model.env.searchModel.resModel + var tr_list = $('.o_data_row') + var current_tr; + var self = this; this.orm.call("color.picker","search_read",[],{ - domain: [ + domain: [ ['res_model', '=',current_model], - ], - }).then(function(data){ - for(var i=0;i { + if (tr.firstChild.nextElementSibling.dataset.id == item.record_id) { + tr.style.backgroundColor = item.color + } + }); + }); }) - }, - -}) +}) \ No newline at end of file diff --git a/listview_change_background_color/static/src/xml/color_picker.xml b/listview_change_background_color/static/src/xml/color_picker.xml index c187bbbc2..16e3f2d87 100644 --- a/listview_change_background_color/static/src/xml/color_picker.xml +++ b/listview_change_background_color/static/src/xml/color_picker.xml @@ -1,20 +1,26 @@ - + - Color + Color - - + + - + - - + +