Edi Santoso
Odoo and Python Developer
drink a tea to enjoying the life

Odoo Hide Form Button Edit or Create based on condition

 you can inherit the python file

class StockPicking(models.Model):

    _inherit = 'stock.picking'


    def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

        res = super(StockPicking, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

        if view_type == 'form':

            context = dict(self._context or {})

            pickingId = context.get('params', {}).get('id')

            if pickingId:

                Picking = self.browse(pickingId)

                is_disable_edit = Picking.internal_transfer_type == 'incoming' and Picking.is_inter_receive == True

                if is_disable_edit:

                    root = etree.fromstring(res['arch'])

                    root.set('edit', 'false')

                    res['arch'] = etree.tostring(root)

        return res