[IMP] server_action_navigate

Co-authored-by: Holger Brunn <mail@hunki-enterprises.com>

[IMP] tests
This commit is contained in:
Sylvain LE GAL
2020-07-25 11:16:32 +02:00
committed by Quentin Tawry
parent bf8af4757c
commit de4e9ffd40
6 changed files with 68 additions and 27 deletions

View File

@@ -2,7 +2,7 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import api, fields, models
class IrActionsServerNavigateLine(models.Model):
@@ -10,14 +10,7 @@ class IrActionsServerNavigateLine(models.Model):
_description = "Server Actions Navigation Lines"
_order = "sequence"
sequence = fields.Integer(string="Sequence", default=9999)
sequence2 = fields.Integer(
related='sequence',
string="Line Number",
readonly=True,
store=True,
)
sequence = fields.Integer(string="Sequence", default=1)
field_model = fields.Char(
string="Model", related="field_id.relation", store=True)
@@ -29,3 +22,23 @@ class IrActionsServerNavigateLine(models.Model):
field_id = fields.Many2one(
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')
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', []),
)
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),
],
}
}