This question has been flagged
6 Replies
21899 Views

For example:

the officer can only drag from

Draft > Confirmed

and the manager can drag from

Confirmed > Approved or Rejected


If they are not permitted to for the stages they can't drag any data from one stage to another.

Is there a way for this?

Avatar
Discard
Best Answer

Hi,

To Restrict drag and drop in the kanban view in Odoo10, 11 and 12, you can use this free module from the store: https://apps.odoo.com/apps/modules/11.0/kanban_draggable/


To disable drag drop record between columns add:
    disable_drag_drop_record="true" into the <kanban> tag.

To disable drag drop and sorting records add :
    disable_sort_record="true" into the <kanban> tag.

To disable sorting columns add :
    disable_sort_column="true" into the <kanban> tag.

Example:
    <kanban disable_sort_column='true' disable_sort_record='true' disable_drag_drop_record='true'>
    ...
    ...
    </kanban>


From odoo13, we have an option by default to do this. Set records_draggable to False.

``records_draggable``
whether it should be possible to drag records when kanban is grouped. Default: true.


See the Video Explaining the same:  How to Disable Drag and Drop in Odoo Kanban View

Thanks

Avatar
Discard
Best Answer

Hello! Here is an example for the case your stage field is a Selection with this values [('draft','Draft'), ('confirm','Confirmed'), ('approved','Approved'),('rejected','Rejected')]:

@api.multi
def write(self, values):
if 'state' in values:
        previous_state = self.state
        new_state = values.get('state')
if (new_state in ['approved','rejected']) and (not self.env.user.has_group('your_module.your_group_xml_id')):
            raise ValidationError(_("Only Managers can perform that move !"))
#elif some other_conditions:
            #some other logics
return super(YOUR CLASS, self).write(values)
for stages of type Many2one, you would need to use the ids for comparison. eg:
current_stage = self.stage_id
new_stage_id = values.get('stage_id')
if new_stage_id == self.env.ref('your_module.xml_id_of_your_stage').id:
     raise UserError(_('Message here'))

Avatar
Discard
Best Answer

It's also possible with Automated Actions, as explained here (this is a more complex example with validation, but it could be simplified):

This example has a “Financial Viability” check and a “Legal Approval” check that are mandatory before the Lead / Opportunity can be moved to one of the later stages.

Start by creating an Automated Action:

Python Code

# Require Financial Viability
if record.stage_id.name in ['Qualified', 'Proposition', 'Won'] and not record.x_studio_financial_viability:
    raise Warning('Please check Financial Viability for this Opportunity!')

# Require Legal Approval
if record.stage_id.name in ['Proposition', 'Won'] and not record.x_studio_legal_approval:
    raise Warning('Please check Legal Approval for this Opportunity!')

Odoo 14

Note that the syntax is slightly different in Odoo 14

raise UserError('Please check Legal Approval for this Opportunity!')

Results

Set the “Financial Viability” as checked, and stage can be changed:

 

Validation is done when the stage is changed in the Kanban view (as above).

It’s also done in the Form View:

The check will be done everywhere and cannot be overridden. 

Avatar
Discard
Best Answer

Hi,

You can check that in the write function of the model. and raise an error.

for eg:

@api.multi
def write(self, values):
if (YOUR CONDITION):
            raise ValidationError(_("You can't perform that move !"))
return super(YOUR CLASS, self).write(values)

Thank you.

Avatar
Discard
Author

can you give me an example of condition to put. I don't know how to start. thank you in advance

Best Answer

What about:

<field name="stage" attrs="{'readonly': [('group_ids','in',[g.id for g in user.groups_id])]}"/> 
Avatar
Discard
Best Answer

you can stop that by modifying the attribute of stage_id for example

   


<field name="stage_id" position="attributes">
<attribute name="readonly">True</attribute>
</field>
Avatar
Discard