GoodERP
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

157 rindas
7.0KB

  1. from odoo.tests.common import TransactionCase
  2. from odoo.exceptions import UserError
  3. import operator
  4. class TestReport(TransactionCase):
  5. def setUp(self):
  6. super(TestReport, self).setUp()
  7. self.env.ref('core.goods_category_1').account_id = self.env.ref(
  8. 'finance.account_goods').id
  9. self.env.ref('warehouse.wh_in_whin0').date = '2016-02-06'
  10. self.env.ref('warehouse.wh_in_whin3').date = '2016-02-06'
  11. self.env.ref('warehouse.wh_in_whin1').date = '2016-02-06'
  12. self.env.ref('warehouse.wh_in_wh_in_attribute').date = '2016-02-06'
  13. # 商品 仓库 批号 数量 类型
  14. # 键鼠套装 总仓 96 入库
  15. # 网线 总仓 11928 入库
  16. # 网线 总仓 120 出库
  17. # 网线 上海仓 120 入库
  18. # 键盘 总仓 kb160000567 600 入库
  19. # 鼠标 总仓 ms160301 1 入库
  20. # 鼠标 总仓 ms160302 1 入库
  21. self.env['wh.in'].search(
  22. [('name', '!=', 'WH/IN/16040004')]).approve_order()
  23. # 先盘点商品,保证网线数量充足
  24. warehouse_obj = self.env.ref('warehouse.wh_in_whin0')
  25. # warehouse_obj.approve_order()
  26. self.env['wh.internal'].search([]).approve_order()
  27. ''' odoo13 必须在这里read一下后面sql才能取到数据 '''
  28. for l in self.env['wh.move.line'].search([]):
  29. l.read()
  30. self.transceive_wizard = self.env['report.stock.transceive.wizard'].create({
  31. 'date_start': '2016-04-01',
  32. 'date_end': '2016-04-03'})
  33. def test_report_base(self):
  34. report_base = self.env['report.base'].create({})
  35. self.assertEqual(report_base.select_sql(), '')
  36. self.assertEqual(report_base.from_sql(), '')
  37. self.assertEqual(report_base.where_sql(), '')
  38. self.assertEqual(report_base.group_sql(), '')
  39. self.assertEqual(report_base.order_sql(), '')
  40. self.assertEqual(report_base.get_context(), {})
  41. self.assertEqual(report_base.collect_data_by_sql(), [])
  42. def test_open_report(self):
  43. # 测试商品收发明细表的wizard
  44. self.assertEqual(self.transceive_wizard.onchange_date(), {})
  45. self.transceive_wizard.date_end = '1999-09-09'
  46. results = self.transceive_wizard.onchange_date()
  47. real_results = {'warning': {
  48. 'title': '错误',
  49. 'message': '结束日期不可以小于开始日期'
  50. }, 'value': {'date_end': self.transceive_wizard.date_start}}
  51. self.assertEqual(results, real_results)
  52. self.assertEqual(self.transceive_wizard.open_report().get(
  53. 'res_model'), 'report.stock.transceive')
  54. # 测试wizard默认日期
  55. self.env['report.stock.transceive.wizard'].create({})
  56. def test_stock_transceive_search_read(self):
  57. stock_transceive = self.env['report.stock.transceive'].create({})
  58. self.transceive_wizard.date_start = '2016-02-01'
  59. context = self.transceive_wizard.open_report().get('context')
  60. real_results = [
  61. # 商品 仓库 出库数量 入库数量
  62. ('键盘', '总仓', 0, 600),
  63. ('鼠标', '总仓', 0, 2),
  64. ('网线', '总仓', 0, 12048),
  65. # ('网线', '上海仓', 0, 120),
  66. ('键鼠套装', '总仓', 0, 96),
  67. ]
  68. results = stock_transceive.with_context(context).search_read(domain=[])
  69. length = stock_transceive.with_context(context).search_count(domain=[])
  70. self.assertEqual(len(results), len(real_results))
  71. self.assertEqual(len(results), length)
  72. instance = stock_transceive.with_context(
  73. context).browse(results[0].get('id'))
  74. self.assertEqual(instance.read(['warehouse'])[0].get(
  75. 'warehouse'), results[0].get('warehouse'))
  76. for result in results:
  77. result = (
  78. result.get('goods'),
  79. result.get('warehouse'),
  80. result.get('goods_qty_out'),
  81. result.get('goods_qty_in'),
  82. )
  83. self.assertTrue(result in real_results)
  84. stock_transceive.with_context(context).find_source_move_line()
  85. def test_stock_transceive_search_by_goods_warehouse(self):
  86. """
  87. 商品收发明细表:按商品和仓库查询
  88. """
  89. self.transceive_wizard.date_start = '2016-02-01'
  90. self.transceive_wizard.goods_id = self.env.ref('goods.mouse').id
  91. self.transceive_wizard.warehouse_id = self.env.ref(
  92. 'warehouse.hd_stock').id
  93. context = self.transceive_wizard.open_report().get('context')
  94. stock_transceive = self.env['report.stock.transceive'].create({})
  95. results = stock_transceive.with_context(context).search_read(domain=[])
  96. self.assertEqual(len(results), 1)
  97. # 查看库存调拨明细
  98. stock_transceive.with_context(context).find_source_move_line()
  99. def test_stock_transceive_search_read_domain(self):
  100. """
  101. 商品收发明细表:额外增加domain
  102. """
  103. self.transceive_wizard.date_start = '2016-02-01'
  104. context = self.transceive_wizard.open_report().get('context')
  105. stock_transceive = self.env['report.stock.transceive'].create({})
  106. # 增加一个domain 条件
  107. result1 = stock_transceive.with_context(
  108. context).search_read(domain=[('warehouse', '=', '上海仓')])
  109. # 增加一个domain 条件,domain 中用‘|’
  110. result2 = stock_transceive.with_context(context).search_read(
  111. domain=['|', ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
  112. # with self.assertRaises(UserError): # 暂时无法解析的domain条件
  113. # stock_transceive.with_context(context).search_read(
  114. # domain=[('warehouse', '<>', '上海仓')])
  115. # with self.assertRaises(UserError): # 不可识别的domain条件
  116. # stock_transceive.with_context(context).search_read(
  117. # domain=[('warehouse', '=', '上海仓', 'xxx')])
  118. # with self.assertRaises(UserError): # 不可识别的domain条件
  119. # stock_transceive.with_context(context).search_read(
  120. # domain=['warehouse', '=', '上海仓'])
  121. # 增加一个domain 条件,domain 中用'|','|'
  122. stock_transceive.with_context(context).search_read(
  123. domain=['|', '|', ('goods', '=', '键盘'), ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
  124. def test_stock_transceive_read_group(self):
  125. """
  126. 商品收发明细表: 按商品和仓库分组
  127. """
  128. self.transceive_wizard.date_start = '2016-02-01'
  129. context = self.transceive_wizard.open_report().get('context')
  130. stock_transceive = self.env['report.stock.transceive'].create({})
  131. stock_transceive.with_context(context).read_group(
  132. domain=[('warehouse', '=', '上海仓')],
  133. fields=['warehouse'],
  134. groupby=['warehouse', 'goods'],
  135. orderby='warehouse',
  136. )
上海开阖软件有限公司 沪ICP备12045867号-1