Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
13008 Ansichten

Hi,

  I need to make all the fields in the entire form read-only when   the state is done.I know we can do it by adding attrs="{'readonly':[('state','=','done']}" for each field. But i am looking for another method.i tried by adding record rule.But it doesn't work at all.

Avatar
Verwerfen
Beste Antwort

If the question was about edit-ability - and ir.rule does not work for you (as it did not work for me, trying and searching for hours), then you can extend the write method:

    @api.multi
    def write(self, vals):
        if any(state == 'done' for state in set(self.mapped('state'))):
            raise UserError(_("No edit in done state"))
        else:
            return super().write(vals)

Trying to edit in done state will result in the Alert with your User Error message.

Avatar
Verwerfen

I used your suggestion Michael, and it worked fabulously. I went alittle further with it to check against called methods, something like this:

@api.multi

def write(self, vals):

invoice_refund = request.params.get('method') in 'invoice_refund'

move_reconcile = request.params.get('method') in ('assign_outstanding_credit', 'remove_move_reconcile')

group_account_edit = self.env.user.has_group('custom_sec_group.group_account_edit')

_logger.debug('Requested params method: [%s.%s]' % (request.params.get('model'), request.params.get('method')))

_logger.debug('Allow invoice_refund method: %s', invoice_refund)

if any(state != 'draft' for state in set(self.mapped('state'))

if not (group_account_edit or invoice_refund or move_reconcile)):

raise UserError(_('Edit allowed only in draft state. [%s.%s]' % (request.params.get('model'), request.params.get('method'))))

else:

_logger.info('Written vals: %s', vals)

return super().write(vals)

Hi, where should I put this write method?

@cteng You'll need to extend the model for which you want to disallow editing and override the write there.

Beste Antwort

@Michale Jurke, I tried your solution but got:
`AttributeError: module 'odoo.api' has no attribute 'multi'` 

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Okt. 18
2822
3
Okt. 18
3672
1
März 18
4404
0
Nov. 17
2511
2
Apr. 23
11442