Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
5579 Zobrazení

Want to put "Delete" action in the last, is there any way to do it?
I tried sequence=1, action is report one,

Not working in my report action, throwing error:
ValueError: Invalid field 'sequence' on model 'ir.actions.report'

See the image: https://imgur.com/a/NXAtFgt


(If image link is blocked by forum because of my karma, kindly paste it in new tab)


Avatar
Zrušit

You can add sequence to server action :)

Nejlepší odpověď

Hey,
I have almost the same answer, but if you need to rewrite already existing reports order / add new ones here is few steps.
1. add sequence int field in 'ir.actions.report' model
2. override get_bindings function in 'ir.actions.actions' model, to order by sequences: 

class IrActions(models.Model):
    _inherit = 'ir.actions.actions'

    @api.model
    def get_bindings(self, model_name):
        result = super(IrActions, self).get_bindings(model_name)
        if result.get('report'):
            result['report'] = sorted(result.get('report'),
                                      key=lambda x: x['sequence'])
        return result

3. after implementing this function the only thing is to do is to add sequence values to the report, add sequence field in 'ir.actions.report' model and set sequence for each report object ( which you need). Ofc you can use already existing reports by using its id


Hope will help :) 

Avatar
Zrušit
Nejlepší odpověď

Hi,

Yes it is possible to add sequence to the custom server action created.Please refer

<record id="action_set_export_contacts" model="ir.actions.server">


    <field name="name">Export Contact to Google Connector</field>


    <field name="model_id" ref="model_res_partner"/>


    <field name="binding_model_id" ref="base.model_res_partner"/>


    <field name="sequence">4</field>


    <field name="state">code</field>


    <field name="code">


            action = model.action_export_contacts()


    </field>


</record>


Regards

Avatar
Zrušit
Nejlepší odpověď

To change the order of actions on a form, you can use the sequence field. However, the sequence field is not available on the ir.actions.report model, which is the model for report actions.

As a workaround, you can try to create a new action that inherits from the ir.actions.report model and adds the sequence field. You can then use this new action for your reports and set the sequence value to control the order of the actions.

Here is an example of how you can do this:

  1. Create a new model that inherits from ir.actions.report and adds the sequence field:
class ReportAction(models.Model):
    _inherit = 'ir.actions.report'

    sequence = fields.Integer()
  1. Update the ir.actions.act_window model to use the new ReportAction model instead of the default ir.actions.report model:
class ActWindow(models.Model):
    _inherit = 'ir.actions.act_window'

    report_id = fields.Many2one('report.action', 'Report')
  1. When creating a new report action, use the ReportAction model instead of the ir.actions.report model and set the sequence value to control the order of the actions:
ReportAction.create({
    'name': 'My Report',
    'model': 'my.model',
    'report_type': 'qweb-pdf',
    'sequence': 1,
})

This should allow you to control the order of the actions on the form using the sequence field.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
4
bře 24
14678
0
kvě 21
2366
2
zář 20
3325
1
led 20
4230
0
dub 25
681