İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
13015 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç

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.

En İyi Yanıt

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

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Eki 18
2824
3
Eki 18
3677
1
Mar 18
4411
0
Kas 17
2515
2
Nis 23
11445