product_variant.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # coding: utf-8
  2. # © 2015 Abdessamad HILALI <abdessamad.hilali@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api
  5. from lxml import etree
  6. from openerp.osv import orm
  7. class ProductProduct(models.Model):
  8. _inherit = 'product.product'
  9. @api.multi
  10. def button_activate(self):
  11. self.write({'active': True})
  12. @api.multi
  13. def button_deactivate(self):
  14. self.write({'active': False})
  15. @api.model
  16. def fields_view_get(self, view_id=None, view_type='tree',
  17. toolbar=False, submenu=False):
  18. """ Dynamic modification of fields """
  19. res = super(ProductProduct, self).fields_view_get(
  20. view_id=view_id, view_type=view_type,
  21. toolbar=toolbar, submenu=submenu)
  22. root = etree.fromstring(res['arch'])
  23. if view_type == 'tree':
  24. for button in root.findall(".//button"):
  25. # search_disable_custom_filters is applied when active_id/ids
  26. # defined in addons/web/static/src/js/views.js
  27. if 'search_disable_custom_filters' in self.env.context:
  28. button.set('invisible', '0')
  29. orm.setup_modifiers(button, root)
  30. res['arch'] = etree.tostring(root, pretty_print=True)
  31. return res