[IMP] base: sort actions by sequence if sequence available

before this commit:
actions are not showing as per the sequence, like:
1) Other actions (delete, duplicate)
2) Windows actions
3) Server actions (without sorting by sequence)

After this commit:
Server actions are sorted by the sequence, like:
1) Other actions (delete, duplicate)
2) Windows actions
3) Server actions (with sorting by sequence)

task-2005419

closes odoo/odoo#39872

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Priyanka Kakadiya
2020-03-23 12:15:38 +00:00
committed by Raphael Collet
parent 8f8c93b68a
commit 85c707e684
2 changed files with 17 additions and 0 deletions
+3
View File
@@ -129,6 +129,9 @@ class IrActions(models.Model):
except (AccessError, MissingError):
continue
# sort actions by their sequence if sequence available
if result.get('action'):
result['action'] = sorted(result['action'], key=lambda vals: vals.get('sequence', 0))
return result
+14
View File
@@ -252,7 +252,21 @@ class TestServerActions(TestServerActionsBase):
self.action.with_context(self.context).run()
self.assertEqual(self.test_country.vat_label, 'VatFromTest', 'vat label should be changed to VatFromTest')
def test_60_sort(self):
""" check the actions sorted by sequence """
Actions = self.env['ir.actions.actions']
# Do: update model
self.action.write({
'model_id': self.res_country_model.id,
'binding_model_id': self.res_country_model.id,
})
self.action2 = self.action.copy({'name': 'TestAction2', 'sequence': 1})
# Test: action returned by sequence
bindings = Actions.get_bindings('res.country')
self.assertEqual([vals.get('name') for vals in bindings['action']], ['TestAction2', 'TestAction'])
self.assertEqual([vals.get('sequence') for vals in bindings['action']], [1, 5])
class TestCustomFields(common.TransactionCase):