1
votes

I am working with stock.move model. This model has a Many2one field named picking_type_id. I know this is not the best way, but I use attrs="{'invisible': [('picking_type_id', '=', 1)]}" expression to hide elements in incoming stock moves (I am pretty sure that incoming type ID is not going to be modified).

But this expression is only working in form views, it does not work for tree views. This would be comprensible if the element is a field, but if not (for example a button), it should work, shouldn't it?

<field name="picking_type_id" invisible="0"/>
<button name="open_lots_manager_wizard"
    string="Select lots" type="object"
    icon="terp-accessories-archiver+"
    attrs="{'invisible': [('picking_type_id', '=', 1)]}"
    groups="stock.group_stock_user"/>

For example if I modify the above attrs expression and turn it into the below one, it works (if I set a quantity over 3, the button disappears, and it appears again if I set a quantity under or equal to 3):

<field name="picking_type_id" invisible="0"/>
<button name="open_lots_manager_wizard"
    string="Select lots" type="object"
    icon="terp-accessories-archiver+"
    attrs="{'invisible': [('product_uom_qty', '>', 3)]}"
    groups="stock.group_stock_user"/>

Can anyone explain me the reason of this? Do I have to create a related field pointing to the picking type code (for example) only to achieve my purpose?

1

1 Answers

1
votes

I tested your code and understand problem. It is better to get the object per XML ID (stock.picking_type_in) and compare it with the picking type in stock move.

My solution looks like this.

test_stock_move.py

# -*- coding: utf-8 -*-
from openerp import models, fields, api, _

class stock_move(models.Model):
    _inherit = "stock.move"

    @api.multi
    @api.depends("picking_type_id")
    def _compute_incoming_type(self):
        for o in self:
            o.is_picking_type_incoming = (o.picking_type_id.id == self.env.ref("stock.picking_type_in").id)

    is_picking_type_incoming = fields.Boolean(_("Is picking type incoming"),compute=_compute_incoming_type)

stock_move_view.xml

<record id="stock_move_tree" model="ir.ui.view">
    <field name="name" >stock.move.form</field>
    <field name="model">stock.move</field>
    <field name="inherit_id" ref="stock.view_move_tree" />
    <field name="arch" type="xml">
        <xpath expr="//field[@name='state']" position="after">
              <field name="is_picking_type_incoming"/>
              <button name="open_lots_manager_wizard"
                  string="Select lots" type="object"
                  icon="terp-accessories-archiver+"
                  attrs="{'invisible': [('is_picking_type_incoming', '=', True)]}"
                  groups="stock.group_stock_user"/>
         </xpath>
    </field>
</record>

I added a new computed field is_picking_type_incoming in stock.move model. That worked in my case. Hopefully it solves your problem.