You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>).
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models
  5. class Module(models.Model):
  6. _inherit = 'ir.module.module'
  7. def module_uninstall(self, cr, uid, ids, context=None):
  8. context = context or {}
  9. for module in self.browse(cr, uid, ids, context=context):
  10. if module.name == 'pos_remove_pos_category':
  11. # As we have loose previous POS categs restore them
  12. # in a sane empty state
  13. cr.execute('UPDATE product_template SET pos_categ_id=NULL')
  14. # And restore original constraint
  15. cr.execute('''
  16. ALTER TABLE product_template
  17. DROP CONSTRAINT IF EXISTS
  18. product_template_pos_categ_id_fkey
  19. ''')
  20. cr.execute('''
  21. ALTER TABLE product_template ADD CONSTRAINT
  22. "product_template_pos_categ_id_fkey"
  23. FOREIGN KEY (pos_categ_id)
  24. REFERENCES pos_category(id) ON DELETE SET NULL;
  25. ''')
  26. # Restore POS category menu action
  27. # in SQL because pool/env is not available here
  28. cr.execute('''
  29. UPDATE ir_act_window iaw SET res_model='pos.category'
  30. FROM ir_model_data imd
  31. WHERE
  32. iaw.id = imd.res_id AND
  33. imd.model = 'ir.actions.act_window' AND
  34. imd.name = 'product_pos_category_action'
  35. ''')
  36. break
  37. return super(Module, self).module_uninstall(
  38. cr, uid, ids, context=context
  39. )