[IMP] server_action_navigate: black, isort, prettier

This commit is contained in:
Quentin Tawry
2021-11-10 14:11:58 +01:00
committed by Sylvain LE GAL
parent b099a40ace
commit f73945cba1
6 changed files with 99 additions and 90 deletions

View File

@@ -13,25 +13,29 @@ class IrActionsServer(models.Model):
navigate_action_id = fields.Many2one(
string="Navigation Action",
comodel_name='ir.actions.act_window',
comodel_name="ir.actions.act_window",
domain="[('res_model', '=', max_navigate_line_model)]",
help="Define here the action used when the navigation will be executed"
" if empty, a generic action will be used.")
" if empty, a generic action will be used.",
)
navigate_line_ids = fields.One2many(
comodel_name="ir.actions.server.navigate.line",
string="Navigate Lines", inverse_name="action_id")
string="Navigate Lines",
inverse_name="action_id",
)
max_navigate_line_sequence = fields.Integer(
string='Max Navigate sequence in lines',
compute='_compute_max_navigate_line',
store=True
string="Max Navigate sequence in lines",
compute="_compute_max_navigate_line",
store=True,
)
max_navigate_line_model = fields.Char(
string="Max Navigate Model in lines",
compute="_compute_max_navigate_line",
store=True)
store=True,
)
@api.depends("navigate_line_ids", "model_id")
def _compute_max_navigate_line(self):
@@ -43,11 +47,13 @@ class IrActionsServer(models.Model):
"""
for action in self:
action.max_navigate_line_sequence = (
max(action.mapped('navigate_line_ids.sequence') or [0]) + 1)
action.max_navigate_line_model =\
action.navigate_line_ids\
and action.navigate_line_ids[-1].field_model\
max(action.mapped("navigate_line_ids.sequence") or [0]) + 1
)
action.max_navigate_line_model = (
action.navigate_line_ids
and action.navigate_line_ids[-1].field_model
or action.model_id.model
)
def delete_last_line(self):
self.ensure_one()
@@ -56,34 +62,34 @@ class IrActionsServer(models.Model):
@api.model
def run_action_navigate_multi(self, action, eval_context=None):
IrModel = self.env['ir.model']
IrModel = self.env["ir.model"]
lines = action.navigate_line_ids
if not lines:
raise UserError(_(
"The Action Server %s is not correctly set\n"
" : No fields defined"))
raise UserError(
_("The Action Server %s is not correctly set\n" " : No fields defined")
)
mapped_field_value = ".".join(lines.mapped("field_id.name"))
item_ids = eval_context['records'].mapped(mapped_field_value).ids
domain = "[('id','in',[" + ','.join(map(str, item_ids)) + "])]"
item_ids = eval_context["records"].mapped(mapped_field_value).ids
domain = "[('id','in',[" + ",".join(map(str, item_ids)) + "])]"
# Use Defined action if defined
if action.navigate_action_id:
return_action = action.navigate_action_id
result = return_action.read()[0]
result['domain'] = domain
result["domain"] = domain
else:
# Otherwise, return a default action
model_name = action.max_navigate_line_model
model = IrModel.search([('model', '=', model_name)])
view_mode = 'tree,form'
model = IrModel.search([("model", "=", model_name)])
view_mode = "tree,form"
result = {
'name': model.name,
'domain': domain,
'res_model': model_name,
'target': 'current',
'type': 'ir.actions.act_window',
'view_mode': view_mode,
"name": model.name,
"domain": domain,
"res_model": model_name,
"target": "current",
"type": "ir.actions.act_window",
"view_mode": view_mode,
}
return result

View File

@@ -12,33 +12,34 @@ class IrActionsServerNavigateLine(models.Model):
sequence = fields.Integer(string="Sequence", default=1)
field_model = fields.Char(
string="Model", related="field_id.relation", store=True)
field_model = fields.Char(string="Model", related="field_id.relation", store=True)
action_id = fields.Many2one(
comodel_name="ir.actions.server", string="Action",
required=True, ondelete="cascade")
comodel_name="ir.actions.server",
string="Action",
required=True,
ondelete="cascade",
)
field_id = fields.Many2one(
comodel_name="ir.model.fields", string="Field",
required=True)
comodel_name="ir.model.fields", string="Field", required=True
)
# when adding a record, onchange is called for every field on the
# form, also in editable list views
@api.onchange('field_id')
@api.onchange("field_id")
def _onchange_field_id(self):
# check out the docstring of this in odoo/models.py
lines = self.action_id.resolve_2many_commands(
'navigate_line_ids',
self.env.context.get('navigate_line_ids', []),
"navigate_line_ids", self.env.context.get("navigate_line_ids", []),
)
lines = sum(map(self.new, lines), self.browse([]))
model = lines[-1:].field_id.relation or self.action_id.model_id.model
return {
'domain': {
'field_id': [
('ttype', 'in', ['many2one', 'one2many', 'many2many']),
('model', '=', model),
"domain": {
"field_id": [
("ttype", "in", ["many2one", "one2many", "many2many"]),
("model", "=", model),
],
}
}