1

i want to colorize this cells, module is "Calendar".

enter image description here

also, this place in views: enter image description here i can do this with adding

options='{"color_field":"color"}'

to field parameters, but it need to calculate color by checking, is attendee accepted or declined. If accepted, color - green, if decline - red. I can check this in field

attendee_ids = fields.One2many(
        'calendar.attendee', 'event_id', 'Participant')

also attendee model enter image description here How can i realize this?

Wald Sin
  • 158
  • 11

2 Answers2

1

You can implement a color field on model calendar.attendee which is the model attendee_ids is related to. The many2many color widget is using integers which are not easy to change IIRC. But for the color field itself should be easy:

class Attendee(models.Model):
    _inherit = "calendar.attendee"
    STATE_COLOR_MAPPING = {
        "needsAction": 0,
        "tentative": 1,
        "declined": 2,
        "accepted": 3,
    }

    color = fields.Integer(compute="_compute_color")

    @api.depends("state")
    def _compute_color(self):
        for attendee in self:
            attendee.color = self.STATE_COLOR_MAPPING.get(attendee.state)

You just have to find out if color index are static and if the possible colors are enough for you.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
1

You can define a new widget that inherits the many2manyattendee to color tags based on the attendee state field

You will need to define the name of the color field and set its value for each attendee (tag)

Example: (many2manyattendee.js)

/** @odoo-module **/

import fieldRegistry from 'web.field_registry';
import relationalFields from 'web.relational_fields';


const STATE_SELECTION = new Map([
    ['needsAction', 0],
    ['tentative', 2],
    ['declined', 1],
    ['accepted', 10]
]);

const Many2ManyAttendeeColored = fieldRegistry.get("many2manyattendee").extend({
    _renderTags: function () {
        var self = this;
        var context = this._getRenderTagsContext();
        this.colorField = 'state_index';
        context.elements.forEach(function(item) {
            item[self.colorField] = STATE_SELECTION.get(self.record.specialData.partner_ids.find(partner => partner.id === item.id).status);
        });
        this._super.apply(this, arguments);
    },
});

fieldRegistry.add('many2many_attendee_colored', Many2ManyAttendeeColored);

To load the JS code, add the following entry to the manifest file:

    'assets': {
        'web.assets_backend': [
            'MODULE_NAME/static/src/js/many2manyattendee.js',

        ],
    }

To use it, change the widget on the partners' field to many2many_attendee_colored

Kenly
  • 24,317
  • 7
  • 44
  • 60
  • can you please watch this issue? https://stackoverflow.com/questions/73183584/odoo-how-in-js-file-get-record-from-db-then-change-it-and-re-write maybe you know, how to solve it? – Wald Sin Aug 03 '22 at 10:08