Akhil Mathew
Akhil Mathew

Reputation: 1659

how to detect the drag and drop event of kanban view in odoo?

Kanban view and kanban cards

If i drag and drop a Kanban card from one column to another column (Anylysis to On progress) how can i detect that a card is moved ?

Upvotes: 1

Views: 2911

Answers (2)

DASADIYA CHAITANYA
DASADIYA CHAITANYA

Reputation: 2892

Basically In your case If you want to add drag and drop event on your kanban card so in this case you must have to set the one field which is as grouping of field like state field or any selection or many2one field using default_group_by="company_id"

default_group_by is mainly used to grouping of kanban card on each stage simmilarity as group_by operation on datbase table.

default_group_by :

whether the kanban view should be grouped if no grouping is specified via the action or the current research. Should be the name of the field to group by when no grouping is otherwise specified.

Potential Problem :

There is however a potential problem. Columns representing groups without any items will not be included. This means users won’t be able to move items to those absent groups, which is probably not what we intended.

Odoo has an answer for this ready - an optional model attribute called _group_by_full.

_group_by_full :

It should be a dictionary, mapping field names (of the fields you use for grouping) to methods returning information about all available groups for those fields.

class Store(models.Model):
    @api.model
    def company_groups(self, present_ids, domain, **kwargs):
        companies = self.env['res.company'].search([]).name_get()
        return companies, None

    _name = 'store'
    _group_by_full = {
        'company_id': company_groups,
    }

    name = fields.Char()
    company_id = fields.Many2many('res.company')

The code above ensures that when displaying store objects grouped by company_id, all available companies will be represented (and not only those already having stores).

The code above ensures that when displaying store objects grouped by company_id, all available companies will be represented (and not only those already having stores).

_group_by_full which is return a two element tuple:

First element :

A list of two element tuples, representing individual groups. Every tuple in the list needs to include the particular group’s value (in our example: id of a particular company) and a user friendly name for the group (in our example: company’s name). That’s why we can use the name_get method, since it returns a list of (object id, object name) tuples.

Second element :

A dictionary mapping the groups’ values to a boolean value, indicating whether the group should be folded in Kanban view. Not including a group in this dictionary has the same meaning as mapping it to False.

For example :

this version of company_groups method would make a group representing a company with id 1 folded in Kanban view:

You can also reference the crm module for a better understanding of crm.lead model as it is a good example of grouping of kanban records for the stage_id field.

Just refer to the below post :

https://www.odoo.com/documentation/8.0/reference/views.html#kanban

http://ludwiktrammer.github.io/odoo/odoo-grouping-kanban-view-empty.html

I hope my answer may be helpful to you :)

Upvotes: 1

StackUP
StackUP

Reputation: 1303

On every drag and drop event set_record() will be called

set_record: function(record) {
    var self = this;
    this.id = record.id;
    this.values = {};
    _.each(record, function(v, k) {
        self.values[k] = {
            value: v
        };
    });
    this.record = this.transform_record(record);
},

src: https://github.com/odoo/odoo/blob/8.0/addons/web_kanban/static/src/js/kanban.js#L894

Upvotes: 1

Related Questions