Friday, 15 June 2012

openerp - How can I dynamically set the tree views delete state? -



openerp - How can I dynamically set the tree views delete state? -

i've set order_line editable , want remove delete button if it's not in draft mode. attempted next delete button remains:

<xpath expr="//field[@name='order_line']//tree" position="attributes"> <attribute name="delete" domain="[(parent.state,'!=','draft')]"/> </xpath>

is possible dynamically set delete=false based on draft state of parent?

i tried this:

<record id="delete_drafts_only" model="ir.rule"> <field name="name">you can delete items draft parents</field> <field name="model_id" ref="sale.model_sale_order_line"/> <field name="global" eval="true"/> <field name="domain_force">[('parent.state', '=', 'draft')]</field> <field name="perm_unlink" eval="true"/> </record>

and

<record id="delete_drafts_only" model="ir.rule"> <field name="name">you can delete items draft parents</field> <field name="model_id" ref="sale.model_sale_order_line"/> <field name="global" eval="true"/> <field name="domain_force">[('parent.state', '!=', 'draft')]</field> <field name="perm_read" eval="true"/> <field name="perm_write" eval="true"/> <field name="perm_create" eval="false"/> <field name="perm_unlink" eval="false"/> </record>

but doesn't seem apply. thing seem working manipulating ir_model_access, toggles globally isn't want.

the "ir.rule" solution wrote works: delete button still remain visible, when seek save, gives exception invalid access.

besides, logic behind different: in order "disable" delete of line should utilize negative logic. worked me:

<record id="delete_drafts_only" model="ir.rule"> <field name="name">you can delete items draft parents</field> <field name="model_id" ref="sale.model_sale_order_line"/> <field name="domain_force">[('state', '=', 'draft')]</field> <field name="groups" eval="[(4,ref('base.group_user'))]"/> <field name="perm_read" eval="false"/> <field name="perm_write" eval="false"/> <field name="perm_create" eval="false"/> <field name="perm_unlink" eval="true"/> </record>

i suppose semantic is:

domain_force field point out records of model have considered perm_* fields indicate operations cannot executed (thus "false" value means operation can executed , vice-versa)

openerp odoo openerp-8

No comments:

Post a Comment