Skip to Content
Menú
This question has been flagged
2 Respostes
11596 Vistes

Hi guys

I dont know what's going on here I tried to set as readonly two buttons when for example I click on it but this dont work.

I have 5 boolean fields to help and I store the True or False option on a database

I have a funtion to update the fields.

 

class account_invoice(osv.osv):
    _inherit = 'account.invoice'
    
    
    _columns = {
        'impressoori' : fields.boolean('Original ja foi impresso'),
        'impressodupl': fields.boolean('Duplicado Impresso'),
        'impressotri' : fields.boolean('Triplicado ja foi impresso'),
        'impressoall' : fields.boolean('Todas as vias ja foram impressas'),
        'impressoseg' : fields.boolean('Segunda via ja impressa')
    }
    
    _defaults = {
        'impressodupl': False,
        'impressoori': False,
        'impressotri': False,
        'impressoall': False,
        'impressoseg': False,
    }

def update_field_all(self, cr, uid, ids,context):
        for invoice in self.browse(cr, uid, ids):
             cr.execute("UPDATE account_invoice SET impressoall = True WHERE id = %d" %(invoice.id) )
             cr.execute("UPDATE account_invoice SET impressodupl = True WHERE id = %d" %(invoice.id) )
             cr.execute("UPDATE account_invoice SET impressotri = True WHERE id = %d" %(invoice.id) )
             cr.execute("UPDATE account_invoice SET impressoori = True WHERE id = %d" %(invoice.id) )
             
             #raise osv.except_osv(_('This is the error title'), _('This is the error message'))
        return True

My Xml file :

record model="ir.ui.view" id="account_invoice_rule_saft_inherit">
            <field name="name">account.invoice.rule.saft.inherit</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
        <notebook colspan="4" position="after">
            <!--<button name="%(account.account_invoices)d" position="replace">-->
        <group col="1">
                <field name="impressodupl" nolabel="0" invisible="False" />
                <field name="impressoori" nolabel="0" invisible="False" />
                <field name="impressotri" nolabel="0" invisible="False" />
                <field name="impressoall" nolabel="0" invisible="False" />
          <field name="impressoseg" nolabel="0" invisible="False" />
          
        </group>
     

                  <button name="%(account_invoices_tri_default)d" type="action" string="Triplicado" icon="gtk-print" states="open,paid,proforma,proforma2" attrs="{'readonly':[('impressoall', '=', True)]}"/>

                  <button name="account_invoices_all_default" type="action" string="Todas as Vias" icon="gtk-print" attrs="{'readonly':[('impressoall', '=', True)]}" states="open,paid,proforma,proforma2" />

                 
          </notebook>
               </field>
        </record>

Avatar
Descartar
Best Answer

I don't know if it is possible to set the readonly attribute to a button. Why don't you try to make them invisible instead? If you don't want users to click on buttons, it would be less confusing not to show the buttons at all...

_____

Answering to your question. Working with the invisible attribute might be a little more chalenging (even more if you have a complex condition involving more fields). You have to think this way (it helps me): you previously wanted to lock a button when a condition was true. Now, what you want is to "not show" that same button. So, what you have to do to make it work, is to reverse your previous logic.

This way, where you had `attrs="{'readonly':[('impressoall', '=', True)]}"` you have to deny that and will have `attrs="{'invisible':[('impressoall', '!=', True)]}"` or `attrs="{'invisible':[('impressoall', '=', False)]}"

__________

Yep, you're right! Forgot that you have to remove the `states="open,paid,proforma,proforma2"` part (wich will transform into an 'invisible' attrs) and join that in your attrs declaration. It should look something like

`attrs="{'invisible':['|', ('impressoall', '=', False), ('state', 'not in', ['open','paid','proforma','proforma2'])]}"`

Avatar
Descartar
Autor Best Answer

But How? I put ttrs="{'invisible':[('impressoall', '=', True)]}" and it dont work... strange

-----------------------------------------------------------------------------------------------------------------------------------

ok the problem was the state..... It force the buttons apear all the time...

I put the state inside the attrs thx by the way you help me too :)

Avatar
Descartar

how did you add the states inside the attrs??

how did you add the states inside the attrs??

@alcalinelee, read the final paragraph of my answer above. The `states="some_state` part will be converted into an invisible attribute, so you have to remove it from your button definition and insert it into the attrs part.

Related Posts Respostes Vistes Activitat
1
d’oct. 24
1495
4
de juny 24
2963
2
de març 23
9981
2
de març 23
2414
2
de maig 22
4351