GoodERP
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

51 lines
2.9KB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2026 南京欧度易网络科技有限公司 (http://www.intoerp.com)
  3. # 作者: ccdos@intoerp.com 单雷平
  4. """Report results must follow the current transaction and own their row data."""
  5. from odoo import api
  6. from odoo.tests.common import TransactionCase
  7. class TestReportIsolation(TransactionCase):
  8. def setUp(self):
  9. super().setUp()
  10. unit = self.env['uom'].create({'name': '报表隔离测试件'})
  11. category = self.env['core.category'].create({'name': '报表隔离测试类', 'type': 'goods'})
  12. optional_goods = {}
  13. if 'supplier_id' in self.env['goods']._fields:
  14. supplier_category = self.env['core.category'].create({'name': '原生回归供应商类', 'type': 'supplier'})
  15. supplier = self.env['partner'].create({'name': '原生回归供应商', 's_category_id': supplier_category.id})
  16. optional_goods['supplier_id'] = supplier.id
  17. goods = self.env['goods'].create({'name': '报表隔离测试物料', 'code': 'REPORT-ISOLATION',
  18. 'uom_id': unit.id, 'category_id': category.id, **optional_goods})
  19. stock = self.env['warehouse'].create({'name': '报表隔离测试仓', 'type': 'stock'})
  20. supplier = self.env.ref('warehouse.warehouse_supplier')
  21. move = self.env['wh.move'].create({'warehouse_id': supplier.id, 'warehouse_dest_id': stock.id, 'origin': 'buy.receipt.buy'})
  22. # A report-only ledger fixture: this suite tests SQL visibility, not receipt approval.
  23. self.line = self.env['wh.move.line'].create({'move_id': move.id, 'type': 'in',
  24. 'warehouse_id': supplier.id, 'warehouse_dest_id': stock.id,
  25. 'goods_id': goods.id, 'uom_id': unit.id, 'goods_qty': 5,
  26. 'cost_unit': 1, 'cost': 5, 'state': 'done', 'date': '2026-01-02'})
  27. self.report = self.env['buy.summary.goods'].with_context(
  28. goods_id=(goods.id, goods.name), warehouse_dest_id=(stock.id, stock.name),
  29. date_start='2026-01-01', date_end='2026-01-31')
  30. self.env.flush_all()
  31. def test_read_after_ledger_change(self):
  32. self.assertEqual(self.report.search_read([])[0]['qty'], 5)
  33. self.line.goods_qty = 7
  34. self.env.flush_all()
  35. self.assertEqual(self.report.search_read([])[0]['qty'], 7)
  36. def test_rows_are_not_shared_with_callers(self):
  37. rows = self.report.get_data_from_cache()
  38. rows[0]['qty'] = 999
  39. self.assertEqual(self.report.get_data_from_cache()[0]['qty'], 5)
  40. def test_new_transaction_does_not_receive_uncommitted_cached_rows(self):
  41. self.assertEqual(len(self.report.search_read([])), 1)
  42. with self.registry.cursor() as cr:
  43. other = api.Environment(cr, self.env.uid, dict(self.report.env.context))
  44. # This independent transaction cannot see the test's uncommitted ledger.
  45. self.assertFalse(other['buy.summary.goods'].search_read([]))
上海开阖软件有限公司 沪ICP备12045867号-1