Hi,
We allow users to do a “pick” on inventory moves on customer shipment (custom code). So, we add a button ‘pick’ on the model ‘stock.move’. Those button should be only active/visible when move is in state ‘assigned’ and move is an inventory move.
So i define a function field to test if move is an inventory move out:
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
...
is_inventory_move_out = fields.Function(
fields.Boolean("Is Inventory Move Out"),
'on_change_with_is_inventory_move_out')
@classmethod
def __setup__(cls):
super().__setup__()
cls._buttons.update({
'pick': {
'readonly': (~Eval('state').in_(['assigned'])
| ~Eval('is_inventory_move_out', False)),
'depends': ['state', 'is_inventory_move_out'],
},
})
@fields.depends('shipment')
def on_change_with_is_inventory_move_out(self, name=None):
if self.shipment:
if getattr(self.shipment, 'warehouse_output', None):
return self.shipment.warehouse_output == self.to_location
return False
@classmethod
@ModelView.button_action('preciball.wizard_pick')
def pick(cls, moves):
pass
Everything seems ok except sometimes button stays ‘readonly’ (Pyson conditions are ok) and user has to close-reopen the customer shipment tab to get the button active.
Any idea why sometimes ‘readonly’ state of button is incorrect ?
Do I need to use another method to test if the current move is an inventory move out ? (I guess this is the function field which makes the condition sometimes wrong).