test_uninstall.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from unittest.mock import patch
  4. from odoo import fields
  5. from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
  6. from odoo.addons.purchase_stock.models.purchase import PurchaseOrderLine
  7. from odoo.tests.common import tagged
  8. from .common import PurchaseTestCommon
  9. @tagged('post_install', '-at_install')
  10. class TestUninstallPurchaseStock(PurchaseTestCommon):
  11. def test_qty_received_method(self):
  12. partner = self.env['res.partner'].create({'name': 'Test Partner'})
  13. purchase_order = self.env['purchase.order'].create({
  14. 'partner_id': partner.id,
  15. 'state': 'purchase',
  16. 'order_line': [fields.Command.create({
  17. 'product_id': self.product_1.id,
  18. })],
  19. })
  20. order_line = purchase_order.order_line
  21. stock_move = order_line.move_ids
  22. self.assertEqual(order_line.product_id.detailed_type, 'product')
  23. stock_move.quantity_done = 1
  24. stock_move.picking_id.button_validate()
  25. self.assertEqual(purchase_order.order_line.qty_received, 1)
  26. stock_moves_option = self.env['ir.model.fields.selection'].search([
  27. ('field_id.model', '=', 'purchase.order.line'),
  28. ('field_id.name', '=', 'qty_received_method'),
  29. ('value', '=', 'stock_moves'),
  30. ])
  31. original_compute = PurchaseOrderLine._compute_qty_received
  32. def _compute_qty_received(records):
  33. records.read()
  34. with self.assertQueryCount(0):
  35. original_compute(records)
  36. records.flush_recordset()
  37. with patch.object(PurchaseOrderLine, '_compute_qty_received', _compute_qty_received):
  38. stock_moves_option.sudo().with_context(**{
  39. MODULE_UNINSTALL_FLAG: True
  40. }).unlink()
  41. self.assertEqual(order_line.qty_received_method, 'manual')
  42. self.assertEqual(order_line.qty_received, 1)