You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

  1. # Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class IrActionsServerNavigateLine(models.Model):
  6. _name = "ir.actions.server.navigate.line"
  7. _description = "Server Actions Navigation Lines"
  8. _order = "sequence, id"
  9. sequence = fields.Integer(string="Sequence")
  10. field_model = fields.Char(string="Model", related="field_id.relation", store=True)
  11. action_id = fields.Many2one(
  12. comodel_name="ir.actions.server",
  13. string="Action",
  14. required=True,
  15. ondelete="cascade",
  16. )
  17. field_id = fields.Many2one(
  18. comodel_name="ir.model.fields",
  19. string="Field",
  20. required=True,
  21. ondelete="cascade",
  22. )
  23. # when adding a record, onchange is called for every field on the
  24. # form, also in editable list views
  25. @api.onchange("field_id")
  26. def _onchange_field_id(self):
  27. lines = self.action_id.new(
  28. {"navigate_line_ids": self.env.context.get("navigate_line_ids", [])}
  29. ).navigate_line_ids
  30. model = lines[-1:].field_id.relation or self.action_id.model_id.model
  31. return {
  32. "domain": {
  33. "field_id": [
  34. ("ttype", "in", ["many2one", "one2many", "many2many"]),
  35. ("model", "=", model),
  36. ],
  37. }
  38. }