mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] server_action_navigate
Co-authored-by: Holger Brunn <mail@hunki-enterprises.com> [IMP] tests
This commit is contained in:
committed by
Quentin Tawry
parent
bf8af4757c
commit
de4e9ffd40
@@ -58,7 +58,7 @@ class IrActionsServer(models.Model):
|
|||||||
def run_action_navigate_multi(self, action, eval_context=None):
|
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
|
lines = action.navigate_line_ids
|
||||||
if len(lines) == 0:
|
if not lines:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"The Action Server %s is not correctly set\n"
|
"The Action Server %s is not correctly set\n"
|
||||||
" : No fields defined"))
|
" : No fields defined"))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
|
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# 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):
|
class IrActionsServerNavigateLine(models.Model):
|
||||||
@@ -10,14 +10,7 @@ class IrActionsServerNavigateLine(models.Model):
|
|||||||
_description = "Server Actions Navigation Lines"
|
_description = "Server Actions Navigation Lines"
|
||||||
_order = "sequence"
|
_order = "sequence"
|
||||||
|
|
||||||
sequence = fields.Integer(string="Sequence", default=9999)
|
sequence = fields.Integer(string="Sequence", default=1)
|
||||||
|
|
||||||
sequence2 = fields.Integer(
|
|
||||||
related='sequence',
|
|
||||||
string="Line Number",
|
|
||||||
readonly=True,
|
|
||||||
store=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
field_model = fields.Char(
|
field_model = fields.Char(
|
||||||
string="Model", related="field_id.relation", store=True)
|
string="Model", related="field_id.relation", store=True)
|
||||||
@@ -29,3 +22,23 @@ class IrActionsServerNavigateLine(models.Model):
|
|||||||
field_id = fields.Many2one(
|
field_id = fields.Many2one(
|
||||||
comodel_name="ir.model.fields", string="Field",
|
comodel_name="ir.model.fields", string="Field",
|
||||||
required=True)
|
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),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
* Set a name that will be used for the Contextual Action
|
* Set a name that will be used for the Contextual Action
|
||||||
|
|
||||||
* choose a model
|
* Choose a model
|
||||||
|
|
||||||
* Select 'Navigate' option in the field 'Action To Do'
|
* Select 'Navigate' option in the field 'Action To Do'
|
||||||
|
|
||||||
@@ -22,6 +22,6 @@
|
|||||||
|
|
||||||
**Extra options**
|
**Extra options**
|
||||||
|
|
||||||
* you can define groups whose members will have access to that option.
|
* You can define groups whose members will have access to that option.
|
||||||
|
|
||||||
* You can select an action that will be used to display the target field list.
|
* You can select an action that will be used to display the target field list.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
This module provides a generic tools to have the possibility to see a list of
|
This module provides a generic tool to have the possibility to see a list of
|
||||||
items associated to a given selection.
|
records associated to a given selection of records. This is basically the UI version of ``recordset.mapped('field1.field2')``.
|
||||||
|
|
||||||
For exemple, if you use the sale module, you can configure an action to see
|
For example, if you use the sale module, you can configure an action to see
|
||||||
all the products that has been sold for a given selection of sale orders.
|
all the products that have been sold for a given selection of sale orders.
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
|
||||||
class TestModule(TransactionCase):
|
class TestModule(TransactionCase):
|
||||||
|
|
||||||
@@ -18,5 +20,33 @@ class TestModule(TransactionCase):
|
|||||||
active_model="res.users",
|
active_model="res.users",
|
||||||
active_ids=self.users.ids).run()
|
active_ids=self.users.ids).run()
|
||||||
|
|
||||||
self.assertNotEqual(
|
self.assertEqual(result.get("id", False), False)
|
||||||
result.get("domain", False), False)
|
|
||||||
|
self.assertEqual(
|
||||||
|
result.get('res_model', False), 'res.partner.category')
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
safe_eval(result.get('domain', [])),
|
||||||
|
[("id", "in", self.users.mapped("partner_id.category_id").ids)]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_delete_last_line(self):
|
||||||
|
line_qty = len(self.action_server.navigate_line_ids)
|
||||||
|
self.action_server.delete_last_line()
|
||||||
|
self.assertEqual(
|
||||||
|
line_qty - 1,
|
||||||
|
len(self.action_server.navigate_line_ids)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_action_navigate_with_action(self):
|
||||||
|
self.action_server.navigate_action_id = self.env.ref(
|
||||||
|
"base.action_partner_category_form")
|
||||||
|
|
||||||
|
result = self.action_server.with_context(
|
||||||
|
active_model="res.users",
|
||||||
|
active_ids=self.users.ids).run()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
result.get("id", False),
|
||||||
|
self.env.ref("base.action_partner_category_form").id,
|
||||||
|
)
|
||||||
|
|||||||
@@ -18,21 +18,19 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||||||
<group>
|
<group>
|
||||||
<field name="max_navigate_line_sequence" invisible="1"/>
|
<field name="max_navigate_line_sequence" invisible="1"/>
|
||||||
<field name="max_navigate_line_model" invisible="1"/>
|
<field name="max_navigate_line_model" invisible="1"/>
|
||||||
|
<!-- we can check emptyness of a 2many like this since v10 i think /-->
|
||||||
<button name="delete_last_line" string="Delete Last Line" type="object"
|
<button name="delete_last_line" string="Delete Last Line" type="object"
|
||||||
attrs="{'invisible': [('max_navigate_line_sequence', '=', 1)]}"/>
|
attrs="{'invisible': [('navigate_line_ids', '=', [])]}"/>
|
||||||
<field name="navigate_line_ids" context="{'default_sequence': max_navigate_line_sequence}" nolabel="1" colspan="4">
|
<field name="navigate_line_ids" context="{'navigate_line_ids': navigate_line_ids}" nolabel="1" colspan="4">
|
||||||
<tree editable="bottom" delete="false">
|
<tree editable="bottom" delete="false">
|
||||||
<field name="sequence" invisible="1"/>
|
<!-- the handle widget takes care of the sequence /-->
|
||||||
<field name="sequence2"/>
|
<field name="sequence" widget="handle" invisible="True" />
|
||||||
<field name="field_id" domain="[
|
<field name="field_id" />
|
||||||
('model', '=', parent.max_navigate_line_model),
|
|
||||||
('ttype', 'in', ['many2one', 'one2many', 'many2many']),
|
|
||||||
]"/>
|
|
||||||
<field name="field_model"/>
|
<field name="field_model"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
<field name="navigate_action_id"
|
<field name="navigate_action_id"
|
||||||
attrs="{'invisible': [('max_navigate_line_sequence', '=', 1)]}"/>
|
attrs="{'invisible': [('navigate_line_ids', '=', [])]}"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|||||||
Reference in New Issue
Block a user