单击后禁用按钮-ODOO V8



我有此方法:

@api.multi
def account_move_sc5_10(self):
    #if record.state in ('awaitingraw'):
    for record in self:
        #if record.state in ('draft'):
        tempy = record.contract_worksheet.total_alles - record.contract_worksheet.total_totals
        acc_move = self.env['account.move'] 
        move_lines = [
            (0, 0, {
                'name': 'name', # a label so accountant can understand where this line come from
                'debit': tempy or 0.0, # amount of debit
                'credit': 0, # amount of credit
                'account_id': record.transporter.transp_transit.id, #account_id, # account 
                'date': fields.Date.today(), #date,
                'partner_id': record.transporter.id, # partner if there is one
                #'currency_id': currency_id or (account.currency_id.id or False),
            }),
            (0, 0, {
                'name': 'name',
                'debit': 0, 
                'credit': record.contract_worksheet.total_alles or 0.0,
                'account_id': record.transporter.transp_transit.id,
                #'analytic_account_id': context.get('analytic_id', False),
                'date': fields.Date.today(), #date,
                'partner_id': record.transporter.id,
                #'currency_id': currency_id or (account.currency_id.id or False),
            })
        ]
        journal_id = False
        if record.transporter.transp_transit:
            journals = self.env['account.journal'].search([
                ('default_debit_account_id', '=', record.transporter.transp_transit.id)
            ])
            if journals:
                journal_id = journals[0].id
                acc_move.create({
                #'period_id': period_id, #Fiscal period
                    'journal_id': journal_id, #self.aajournal.id, # journal ex: sale journal, cash journal, bank journal....
                    'date': fields.Date.today(),
                    'state': 'draft',
                    'line_id': move_lines, # this is one2many field to account.move.line
                })

我从视图中称为<button string="Account Moves" name="account_move_sc5_10" states="awaitingraw" type="object" class="oe_highlight"/>

我需要单击此按钮后,它应该保持阅读,我知道可以做到这一点,但是使用此account.move方法,我对如何实现它有点困惑。

有什么想法?

如果单击按钮后对您不可见的按钮对您来说是可以的,则可以这样做:

在模型中声明按钮方法为:

的字段
button_clicked = fields.Boolean(
    string='Button clicked',
    default=False,
)

修改按钮调用的方法,只是为了添加此行:

@api.multi
def account_move_sc5_10(self):
    for record in self:
        record.write({
            'button_clicked': True,
        })
        ...

修改按钮所属添加新字段和条件的模型的视图:

<field name="button_clicked" invisible="1"/>
<button string="Account Moves" name="account_move_sc5_10" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('state', 'not in', 'awaitingraw'), ('button_clicked', '=', True)]}"/>

请注意,我已经删除了states参数,这是因为 attrsstates不能一起使用(如果您两者都使用,它们都不会无能为力)。因此,如果没有,请在视图中添加state字段。