From 04299968c6f269be52d8325a67aa0dbf58d172ff Mon Sep 17 00:00:00 2001 From: david Date: Mon, 17 Aug 2020 09:54:42 +0200 Subject: [PATCH 1/2] [FIX] rma: portal views access errors - Portal mail thread needs token config. - Unpublished products will raise AccessError on RMAs portal views for portal users due to record rules. - Ensure active_id when getting actions in rma, since we could come from a context that pollutes the expected active rma id. --- rma/models/rma.py | 25 +++++++++++++++++++------ rma/views/rma_portal_templates.xml | 12 +++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/rma/models/rma.py b/rma/models/rma.py index 8367c5b3..b547b3d4 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -599,7 +599,10 @@ class Rma(models.Model): """Invoked when 'Replace' button in rma form view is clicked.""" self.ensure_one() self._ensure_can_be_replaced() - action = self.env.ref("rma.rma_delivery_wizard_action").read()[0] + # Force active_id to avoid issues when coming from smart buttons + # in other models + action = self.env.ref("rma.rma_delivery_wizard_action").with_context( + active_id=self.id).read()[0] action['name'] = 'Replace product(s)' action['context'] = dict(self.env.context) action['context'].update( @@ -615,7 +618,10 @@ class Rma(models.Model): """ self.ensure_one() self._ensure_can_be_returned() - action = self.env.ref("rma.rma_delivery_wizard_action").read()[0] + # Force active_id to avoid issues when coming from smart buttons + # in other models + action = self.env.ref("rma.rma_delivery_wizard_action").with_context( + active_id=self.id).read()[0] action['context'] = dict(self.env.context) action['context'].update( active_id=self.id, @@ -628,9 +634,12 @@ class Rma(models.Model): """Invoked when 'Split' button in rma form view is clicked.""" self.ensure_one() self._ensure_can_be_split() - action = self.env.ref("rma.rma_split_wizard_action").read()[0] + # Force active_id to avoid issues when coming from smart buttons + # in other models + action = self.env.ref("rma.rma_split_wizard_action").with_context( + active_id=self.id).read()[0] action['context'] = dict(self.env.context) - action['context'].update(active_ids=self.ids) + action['context'].update(active_id=self.id, active_ids=self.ids) return action def action_cancel(self): @@ -663,7 +672,10 @@ class Rma(models.Model): def action_view_receipt(self): """Invoked when 'Receipt' smart button in rma form view is clicked.""" self.ensure_one() - action = self.env.ref('stock.action_picking_tree_all').read()[0] + # Force active_id to avoid issues when coming from smart buttons + # in other models + action = self.env.ref('stock.action_picking_tree_all').with_context( + active_id=self.id).read()[0] action.update( res_id=self.reception_move_id.picking_id.id, view_mode="form", @@ -687,7 +699,8 @@ class Rma(models.Model): def action_view_delivery(self): """Invoked when 'Delivery' smart button in rma form view is clicked.""" - action = self.env.ref('stock.action_picking_tree_all').read()[0] + action = self.env.ref('stock.action_picking_tree_all').with_context( + active_id=self.id).read()[0] picking = self.delivery_move_ids.mapped('picking_id') if len(picking) > 1: action['domain'] = [('id', 'in', picking.ids)] diff --git a/rma/views/rma_portal_templates.xml b/rma/views/rma_portal_templates.xml index 16cff15b..e4ae704e 100644 --- a/rma/views/rma_portal_templates.xml +++ b/rma/views/rma_portal_templates.xml @@ -50,7 +50,8 @@ - + + @@ -132,12 +133,14 @@ -
+ +
Product
- +
@@ -262,6 +265,9 @@

Communication

+ + +
From fe6993e882e799289fb7ee4912a56b0e6924c620 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 18 Aug 2020 12:26:49 +0200 Subject: [PATCH 2/2] [IMP] rma: teams flow - If no RMA Team is set, we'll assign a default one to the new RMA. - A sequence is now used to search for the top team and assign it. - No default user is assigned when it's not in the context (i.e. portal rmas). --- rma/README.rst | 19 ++++++++++++++++-- rma/models/rma.py | 4 +++- rma/models/rma_team.py | 3 ++- rma/readme/USAGE.rst | 19 ++++++++++++++++-- rma/static/description/index.html | 25 ++++++++++++++++++++++-- rma/views/rma_team_views.xml | 11 +++++++++++ rma_sale/wizard/sale_order_rma_wizard.py | 3 --- 7 files changed, 73 insertions(+), 11 deletions(-) diff --git a/rma/README.rst b/rma/README.rst index 788f6684..dea2df0f 100644 --- a/rma/README.rst +++ b/rma/README.rst @@ -89,8 +89,23 @@ An RMA can also be created from a return of a delivery order: Every RMA will be in confirmed state and they will be linked to the returning operation generated previously. -**Note: An RMA can also be created from an incoming email (See configuration -section).** +There are Optional RMA Teams that can be used for: + + - Organize RMAs in sections. + - Subscribe users to notifications. + - Create RMAs from incoming mail to special aliases (See configuration + section). + +To create an RMA Team (RMA Responsible user level required): + + #. Go to *RMA > Configuration > RMA Teams* + #. Create a new team and assign a name, a responsible and members. + #. Subscribe users to notifications, that can be of these subtypes: + + - RMA draft. When a new RMA is created. + - Notes, Debates, Activities. As in standard Odoo. + #. In the list view, use the cross handle to sort RMA Teams. The top team + will be the default one if no team is set. Known issues / Roadmap ====================== diff --git a/rma/models/rma.py b/rma/models/rma.py index b547b3d4..8a9ddcd8 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -55,7 +55,6 @@ class Rma(models.Model): comodel_name="res.users", string="Responsible", track_visibility="always", - default=lambda self: self.env.user, states={ 'locked': [('readonly', True)], 'cancelled': [('readonly', True)], @@ -499,6 +498,9 @@ class Rma(models.Model): ir_sequence = ir_sequence.with_context( force_company=vals['company_id']) vals['name'] = ir_sequence.next_by_code('rma') + # Assign a default team_id which will be the first in the sequence + if "team_id" not in vals: + vals["team_id"] = self.env["rma.team"].search([], limit=1).id return super().create(vals) def copy(self, default=None): diff --git a/rma/models/rma_team.py b/rma/models/rma_team.py index 31b60097..018fa882 100644 --- a/rma/models/rma_team.py +++ b/rma/models/rma_team.py @@ -8,8 +8,9 @@ class RmaTeam(models.Model): _name = "rma.team" _inherit = ['mail.alias.mixin', 'mail.thread'] _description = "RMA Team" - _order = "name" + _order = "sequence, name" + sequence = fields.Integer() name = fields.Char( required=True, translate=True, diff --git a/rma/readme/USAGE.rst b/rma/readme/USAGE.rst index 6e6194a9..aa524e7a 100644 --- a/rma/readme/USAGE.rst +++ b/rma/readme/USAGE.rst @@ -33,5 +33,20 @@ An RMA can also be created from a return of a delivery order: Every RMA will be in confirmed state and they will be linked to the returning operation generated previously. -**Note: An RMA can also be created from an incoming email (See configuration -section).** +There are Optional RMA Teams that can be used for: + + - Organize RMAs in sections. + - Subscribe users to notifications. + - Create RMAs from incoming mail to special aliases (See configuration + section). + +To create an RMA Team (RMA Responsible user level required): + + #. Go to *RMA > Configuration > RMA Teams* + #. Create a new team and assign a name, a responsible and members. + #. Subscribe users to notifications, that can be of these subtypes: + + - RMA draft. When a new RMA is created. + - Notes, Debates, Activities. As in standard Odoo. + #. In the list view, use the cross handle to sort RMA Teams. The top team + will be the default one if no team is set. diff --git a/rma/static/description/index.html b/rma/static/description/index.html index a45186e6..88523ce3 100644 --- a/rma/static/description/index.html +++ b/rma/static/description/index.html @@ -440,8 +440,29 @@ stock location and click on ‘Return’ button. Every RMA will be in confirmed state and they will be linked to the returning operation generated previously. -

Note: An RMA can also be created from an incoming email (See configuration -section).

+

There are Optional RMA Teams that can be used for:

+
+
    +
  • Organize RMAs in sections.
  • +
  • Subscribe users to notifications.
  • +
  • Create RMAs from incoming mail to special aliases (See configuration +section).
  • +
+
+

To create an RMA Team (RMA Responsible user level required):

+
+
    +
  1. Go to RMA > Configuration > RMA Teams
  2. +
  3. Create a new team and assign a name, a responsible and members.
  4. +
  5. Subscribe users to notifications, that can be of these subtypes:
      +
    • RMA draft. When a new RMA is created.
    • +
    • Notes, Debates, Activities. As in standard Odoo.
    • +
    +
  6. +
  7. In the list view, use the cross handle to sort RMA Teams. The top team +will be the default one if no team is set.
  8. +
+

Known issues / Roadmap

diff --git a/rma/views/rma_team_views.xml b/rma/views/rma_team_views.xml index 328e1ee6..9202da2d 100644 --- a/rma/views/rma_team_views.xml +++ b/rma/views/rma_team_views.xml @@ -2,6 +2,17 @@ + + rma.team + + + + + + + + + rma.team.view.form rma.team diff --git a/rma_sale/wizard/sale_order_rma_wizard.py b/rma_sale/wizard/sale_order_rma_wizard.py index 370fee13..df4afefb 100644 --- a/rma_sale/wizard/sale_order_rma_wizard.py +++ b/rma_sale/wizard/sale_order_rma_wizard.py @@ -29,9 +29,6 @@ class SaleOrderRmaWizard(models.TransientModel): default=lambda r: r.order_id.warehouse_id.rma_loc_id.id, ) - def create_rma_from_portal(self): - self.ensure_one() - def create_rma(self, from_portal=None): self.ensure_one() lines = self.line_ids.filtered(lambda r: r.quantity > 0.0)