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.

49 lines
1.7 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 odoo import models
  5. class Module(models.Model):
  6. _inherit = 'ir.module.module'
  7. def module_uninstall(self):
  8. for module in self:
  9. if module.name == 'pos_remove_pos_category':
  10. # As we have loose previous POS categs restore them
  11. # in a sane empty state
  12. self._cr.execute(
  13. 'UPDATE product_template SET pos_categ_id=NULL')
  14. # And restore original constraint
  15. self._cr.execute('''
  16. ALTER TABLE product_template
  17. DROP CONSTRAINT IF EXISTS
  18. product_template_pos_categ_id_fkey
  19. ''')
  20. self._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. self._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()