Skip to content

[18.0][IMP] rma: Allow users without RMA permissions to confirm stock moves not related to RMA - #614

Open
victoralmau wants to merge 1 commit into
OCA:18.0from
Tecnativa:18.0-fix-rma-stock-user
Open

[18.0][IMP] rma: Allow users without RMA permissions to confirm stock moves not related to RMA#614
victoralmau wants to merge 1 commit into
OCA:18.0from
Tecnativa:18.0-fix-rma-stock-user

Conversation

@victoralmau

Copy link
Copy Markdown
Member

Allow users without RMA permissions to confirm stock moves not related to RMA

@Tecnativa

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @pedrobaeza, @chienandalu,
some modules you are maintaining are being modified, check this out!

Comment thread rma/models/stock_move.py Outdated
]
extra_fields = []
_self = self.sudo()
if _self.rma_id:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is self multi-record? And if one to merge has RMA and the other not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to ensure proper compatibility with multi-record.

In my opinion, it's not possible for some items to be linked to an RMA while others aren't; the picking (confirmed) is created from the RMA (inbound or outbound), and the user has RMA permissions.

@victoralmau
victoralmau force-pushed the 18.0-fix-rma-stock-user branch from 73f391a to 82f7aac Compare July 24, 2026 10:08
Comment thread rma/models/stock_move.py
]
extra_fields = []
_self = self.sudo()
if any(move.rma_id for move in _self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why you need to do this? Simply add them always.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use case example:

  • A user with inventory permissions but WITHOUT RMA permissions creates a picking (for outbound, for example) and attempts to confirm it.

The following error occurs:


File "/opt/odoo/auto/addons/stock/models/stock_picking.py", line 1177, in action_confirm
    self.move_ids.filtered(lambda move: move.state == 'draft')._action_confirm()
  File "/opt/odoo/auto/addons/stock/models/stock_move.py", line 1577, in _action_confirm
    moves = self._merge_moves(merge_into=merge_into)
  File "/opt/odoo/auto/addons/stock/models/stock_move.py", line 1219, in _merge_moves
    for __, g in groupby(candidate_moves, key=self._merge_move_itemgetter(distinct_fields)):
  File "/opt/odoo/custom/src/odoo/odoo/tools/misc.py", line 1216, in groupby
    groups[key(elem)].append(elem)
  File "/opt/odoo/auto/addons/stock/models/stock_move.py", line 1183, in <lambda>
    return lambda move: base_getter(move) + tuple(_get_formatted_float_fields(move, f_name, float_precision) for f_name in float_fields)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 7083, in __getitem__
    return self._fields[key].__get__(self)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 4673, in __get__
    return super().__get__(records, owner)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 3111, in __get__
    return super().__get__(records, owner)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1272, in __get__
    recs._fetch_field(self)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4120, in _fetch_field
    self.fetch(fnames)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4158, in fetch
    fetched = self._fetch_query(query, fields_to_fetch)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4269, in _fetch_query
    field.read(fetched)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 4688, in read
    lines = comodel.search_fetch(domain, field_names)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 1778, in search_fetch
    query = self._search(domain, offset=offset, limit=limit, order=order or self._order)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 5812, in _search
    self.browse().check_access('read')
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4444, in check_access
    raise result[1]()
odoo.exceptions.AccessError: You are not allowed to access 'RMA' (rma) records.

In my opinion, the best way to fix this issue is to ensure that if the record (stock.move) does not have any RMA data associated with it, those fields are not added to the _prepare_merge_moves_distinct_fields() method. This will prevent users without RMA permissions from performing processes that are NOT RMA-related.

The test that has been added specifically tests this use case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I thought that the previous sudo already handles that. And now

Comment thread rma/models/stock_move.py
"rma_receiver_ids",
]
extra_fields = []
_self = self.sudo()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do: self = self.sudo(). It's a local variable.

Comment thread rma/models/stock_move.py
]
extra_fields = []
_self = self.sudo()
if any(move.rma_id for move in _self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking twice, if self.rma_id: serves as well, as it's just non falsy if one or several records exist.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But coming again to the main concept, I think this is done for seeing if a move can be merged with other existing ones, so isn't possible that one has rma_id and the other not? You may do a return without RMA.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, only if one of them (stock.move) has any RMA data set will it be important to distinguish it (by adding the corresponding fields to the _prepare_merge_moves_distinct_fields() method) so that they aren't merged; otherwise, it won't matter if those fields aren't in the method, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how the comparison is done. I'm just pointing possible failure reasons. And also because I don't think this will prevent access error. Have you tried without this if if it fails?

@grindtildeath grindtildeath left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a look here since I approved #613 .

IMO this is not right because _prepare_merge_moves_distinct_fields is an api.model function.

@victoralmau

Copy link
Copy Markdown
Member Author

Conclusions:

The way to fix this in stock would be to change base_getter(move) in https://github.com/odoo/odoo/blob/7971be18e4a33ad712fd11d5e7cf597f8c04459f/addons/stock/models/stock_move.py#L1183 to base_getter(move.sudo()) in https://github.com/odoo/odoo/blob/7971be18e4a33ad712fd11d5e7cf597f8c04459f/addons/stock/models/stock_move.py#L1183, but I’m not sure if odoo will accept that change.

Another solution would be to override the _merge_move_itemgetter() method and call it with super, but the underlying problem would still exist.

@grindtildeath

Copy link
Copy Markdown

Hello @victoralmau

The way to fix this in stock would be to change base_getter(move) in https://github.com/odoo/odoo/blob/7971be18e4a33ad712fd11d5e7cf597f8c04459f/addons/stock/models/stock_move.py#L1183 to base_getter(move.sudo()) in https://github.com/odoo/odoo/blob/7971be18e4a33ad712fd11d5e7cf597f8c04459f/addons/stock/models/stock_move.py#L1183, but I’m not sure if odoo will accept that change.

Did you propose this change to Odoo?

Although I agree it would be cleaner, IMO it's not significantly different that just applying sudo on _merge_moves as it's done in #613 to have this module working.

I'd suggest to mention the Odoo PR as a comment in the fix of #613 so that we can merge it instead of keeping 2 open PRs on this repo trying to fix the same issue...

What do you think?

ping @pedrobaeza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants