[FIX] rma: permissions for general users

- Avoid permission blockings on users who doesn't have RMA permissions.
- Add activities view on RMA list.

[UPD] Update rma.pot

rma 12.0.1.3.1
This commit is contained in:
david
2020-08-24 16:17:28 +02:00
committed by Víctor Martínez
parent 942abab42a
commit 3d888947ac
5 changed files with 21 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
{ {
"name": "Return Merchandise Authorization Management", "name": "Return Merchandise Authorization Management",
"summary": "Return Merchandise Authorization (RMA)", "summary": "Return Merchandise Authorization (RMA)",
"version": "12.0.1.3.0", "version": "12.0.1.3.1",
"development_status": "Beta", "development_status": "Beta",
"category": "RMA", "category": "RMA",
"website": "https://github.com/OCA/rma", "website": "https://github.com/OCA/rma",

View File

@@ -1308,7 +1308,7 @@ msgid "The owner of records created upon receiving emails on this alias. If this
msgstr "" msgstr ""
#. module: rma #. module: rma
#: code:addons/rma/models/stock_move.py:60 #: code:addons/rma/models/stock_move.py:64
#, python-format #, python-format
msgid "The quantity done for the product '%s' must be equal to its initial demand because the stock move is linked to an RMA (%s)." msgid "The quantity done for the product '%s' must be equal to its initial demand because the stock move is linked to an RMA (%s)."
msgstr "" msgstr ""

View File

@@ -15,14 +15,16 @@ class AccountInvoice(models.Model):
""" """
precision = self.env['decimal.precision'].precision_get( precision = self.env['decimal.precision'].precision_get(
'Product Unit of Measure') 'Product Unit of Measure')
if self.mapped('invoice_line_ids').filtered( if self.sudo().mapped('invoice_line_ids').filtered(
lambda r: (r.rma_id and float_compare( lambda r: (r.rma_id and float_compare(
r.quantity, r.rma_id.product_uom_qty, precision) < 0)): r.quantity, r.rma_id.product_uom_qty, precision) < 0)):
raise ValidationError( raise ValidationError(
_("There is at least one invoice lines whose quantity is " _("There is at least one invoice lines whose quantity is "
"less than the quantity specified in its linked RMA.")) "less than the quantity specified in its linked RMA."))
res = super().action_invoice_open() res = super().action_invoice_open()
self.mapped('invoice_line_ids.rma_id').write({'state': 'refunded'}) self.sudo().mapped('invoice_line_ids.rma_id').write(
{'state': 'refunded'}
)
return res return res

View File

@@ -30,8 +30,10 @@ class StockMove(models.Model):
) )
def unlink(self): def unlink(self):
rma_receiver = self.mapped('rma_receiver_ids') # A stock user could have no RMA permissions, so the ids wouldn't
rma = self.mapped('rma_id') # be accessible due to record rules.
rma_receiver = self.sudo().mapped('rma_receiver_ids')
rma = self.sudo().mapped('rma_id')
res = super().unlink() res = super().unlink()
rma_receiver.write({'state': 'draft'}) rma_receiver.write({'state': 'draft'})
rma.update_received_state() rma.update_received_state()
@@ -40,7 +42,9 @@ class StockMove(models.Model):
def _action_cancel(self): def _action_cancel(self):
res = super()._action_cancel() res = super()._action_cancel()
cancelled_moves = self.filtered(lambda r: r.state == 'cancel') # A stock user could have no RMA permissions, so the ids wouldn't
# be accessible due to record rules.
cancelled_moves = self.filtered(lambda r: r.state == 'cancel').sudo()
cancelled_moves.mapped('rma_receiver_ids').write({'state': 'draft'}) cancelled_moves.mapped('rma_receiver_ids').write({'state': 'draft'})
cancelled_moves.mapped('rma_id').update_received_state() cancelled_moves.mapped('rma_id').update_received_state()
cancelled_moves.mapped('rma_id').update_replaced_state() cancelled_moves.mapped('rma_id').update_replaced_state()
@@ -53,7 +57,7 @@ class StockMove(models.Model):
""" """
for move in self.filtered( for move in self.filtered(
lambda r: r.state not in ('done', 'cancel')): lambda r: r.state not in ('done', 'cancel')):
rma_receiver = move.rma_receiver_ids rma_receiver = move.rma_receiver_ids.sudo()
if (rma_receiver if (rma_receiver
and move.quantity_done != rma_receiver.product_uom_qty): and move.quantity_done != rma_receiver.product_uom_qty):
raise ValidationError( raise ValidationError(
@@ -63,12 +67,13 @@ class StockMove(models.Model):
% (move.product_id.name, move.rma_receiver_ids.name) % (move.product_id.name, move.rma_receiver_ids.name)
) )
res = super()._action_done() res = super()._action_done()
move_done = self.filtered(lambda r: r.state == 'done') move_done = self.filtered(lambda r: r.state == 'done').sudo()
# set RMAs as received # Set RMAs as received. We sudo so we can grant the operation even
to_be_received = move_done.mapped('rma_receiver_ids').filtered( # if the stock user has no RMA permissions.
to_be_received = move_done.sudo().mapped('rma_receiver_ids').filtered(
lambda r: r.state == 'confirmed') lambda r: r.state == 'confirmed')
to_be_received.write({'state': 'received'}) to_be_received.write({'state': 'received'})
# set RMAs as delivered # Set RMAs as delivered
move_done.mapped('rma_id').update_replaced_state() move_done.mapped('rma_id').update_replaced_state()
move_done.mapped('rma_id').update_returned_state() move_done.mapped('rma_id').update_returned_state()
return res return res
@@ -85,7 +90,7 @@ class StockMove(models.Model):
RMA link id. RMA link id.
""" """
res = super()._prepare_move_split_vals(qty) res = super()._prepare_move_split_vals(qty)
res['rma_id'] = self.rma_id.id res['rma_id'] = self.sudo().rma_id.id
return res return res
def _prepare_return_rma_vals(self, original_picking): def _prepare_return_rma_vals(self, original_picking):

View File

@@ -270,7 +270,7 @@
<field name="name">RMA</field> <field name="name">RMA</field>
<field name="res_model">rma</field> <field name="res_model">rma</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form,pivot,calendar</field> <field name="view_mode">tree,form,pivot,calendar,activity</field>
<field name="context">{"search_default_user_id": uid}</field> <field name="context">{"search_default_user_id": uid}</field>
<field name="help" type="html"> <field name="help" type="html">
<p class="o_view_nocontent_smiling_face"> <p class="o_view_nocontent_smiling_face">