__init__.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from . import models
  4. from . import wizard
  5. from . import report
  6. from . import controller
  7. from . import populate
  8. from odoo import api, SUPERUSER_ID
  9. def _pre_init_mrp(cr):
  10. """ Allow installing MRP in databases with large stock.move table (>1M records)
  11. - Creating the computed+stored field stock_move.is_done and
  12. stock_move.unit_factor is terribly slow with the ORM and leads to "Out of
  13. Memory" crashes
  14. """
  15. cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "is_done" bool;""")
  16. cr.execute("""UPDATE stock_move
  17. SET is_done=COALESCE(state in ('done', 'cancel'), FALSE);""")
  18. cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "unit_factor" double precision;""")
  19. cr.execute("""UPDATE stock_move
  20. SET unit_factor=1;""")
  21. def _create_warehouse_data(cr, registry):
  22. """ This hook is used to add a default manufacture_pull_id, manufacture
  23. picking_type on every warehouse. It is necessary if the mrp module is
  24. installed after some warehouses were already created.
  25. """
  26. env = api.Environment(cr, SUPERUSER_ID, {})
  27. warehouse_ids = env['stock.warehouse'].search([('manufacture_pull_id', '=', False)])
  28. warehouse_ids.write({'manufacture_to_resupply': True})
  29. def uninstall_hook(cr, registry):
  30. env = api.Environment(cr, SUPERUSER_ID, {})
  31. warehouses = env["stock.warehouse"].search([])
  32. pbm_routes = warehouses.mapped("pbm_route_id")
  33. warehouses.write({"pbm_route_id": False})
  34. # Fail unlink means that the route is used somewhere (e.g. route_id on stock.rule). In this case
  35. # we don't try to do anything.
  36. try:
  37. with env.cr.savepoint():
  38. pbm_routes.unlink()
  39. except:
  40. pass