mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] server_action_navigate: Migration to 16.0
This commit is contained in:
@@ -8,11 +8,7 @@ from odoo import api, fields, models
|
||||
class IrActionsServerNavigateLine(models.Model):
|
||||
_name = "ir.actions.server.navigate.line"
|
||||
_description = "Server Actions Navigation Lines"
|
||||
_order = "sequence, id"
|
||||
|
||||
sequence = fields.Integer(string="Sequence")
|
||||
|
||||
field_model = fields.Char(string="Model", related="field_id.relation", store=True)
|
||||
_order = "id"
|
||||
|
||||
action_id = fields.Many2one(
|
||||
comodel_name="ir.actions.server",
|
||||
@@ -21,28 +17,31 @@ class IrActionsServerNavigateLine(models.Model):
|
||||
ondelete="cascade",
|
||||
)
|
||||
|
||||
field_id = fields.Many2one(
|
||||
comodel_name="ir.model.fields",
|
||||
string="Field",
|
||||
required=True,
|
||||
field_domain_model_id = fields.Many2one(
|
||||
string="Field Model",
|
||||
comodel_name="ir.model",
|
||||
ondelete="cascade",
|
||||
compute="_compute_field_domain_model_id",
|
||||
help="Technical field, used as a domain for the 'field' field.",
|
||||
)
|
||||
|
||||
# when adding a record, onchange is called for every field on the
|
||||
# form, also in editable list views
|
||||
@api.onchange("field_id")
|
||||
def _onchange_field_id(self):
|
||||
field_id = fields.Many2one(
|
||||
comodel_name="ir.model.fields",
|
||||
ondelete="cascade",
|
||||
domain="["
|
||||
"('model_id', '=', field_domain_model_id),"
|
||||
" ('ttype', 'in', ['many2one', 'one2many', 'many2many']),"
|
||||
"]",
|
||||
required=True,
|
||||
)
|
||||
|
||||
lines = self.action_id.new(
|
||||
{"navigate_line_ids": self.env.context.get("navigate_line_ids", [])}
|
||||
).navigate_line_ids
|
||||
|
||||
model = lines[-1:].field_id.relation or self.action_id.model_id.model
|
||||
return {
|
||||
"domain": {
|
||||
"field_id": [
|
||||
("ttype", "in", ["many2one", "one2many", "many2many"]),
|
||||
("model", "=", model),
|
||||
],
|
||||
}
|
||||
}
|
||||
@api.depends("action_id.navigate_line_ids.field_id")
|
||||
def _compute_field_domain_model_id(self):
|
||||
IrModel = self.env["ir.model"]
|
||||
for line in self:
|
||||
model = self.action_id.model_id
|
||||
for action_line in self.action_id.navigate_line_ids:
|
||||
if action_line == line:
|
||||
line.field_domain_model_id = model
|
||||
break
|
||||
model = IrModel.search([("model", "=", action_line.field_id.relation)])
|
||||
|
||||
Reference in New Issue
Block a user