GoodERP
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

161 行
7.1KB

  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']
  58. self.transceive_wizard.date_start = '2016-02-01'
  59. action = self.transceive_wizard.open_report()
  60. context = action['context']
  61. real_results = [
  62. # 商品 仓库 出库数量 入库数量
  63. ('键盘', '总仓', 0, 600),
  64. ('鼠标', '总仓', 0, 2),
  65. ('网线', '总仓', 0, 12048),
  66. # ('网线', '上海仓', 0, 120),
  67. ('键鼠套装', '总仓', 0, 96),
  68. ]
  69. results = stock_transceive.with_context(context).search_read(domain=action['domain'])
  70. length = stock_transceive.with_context(context).search_count(domain=action['domain'])
  71. self.assertEqual(len(results), len(real_results), results)
  72. self.assertEqual(len(results), length)
  73. instance = stock_transceive.with_context(
  74. context).browse(results[0].get('id'))
  75. self.assertEqual(instance.read(['warehouse'])[0].get(
  76. 'warehouse'), results[0].get('warehouse'))
  77. for result in results:
  78. result = (
  79. result.get('goods'),
  80. result.get('warehouse'),
  81. result.get('goods_qty_out'),
  82. result.get('goods_qty_in'),
  83. )
  84. self.assertTrue(result in real_results)
  85. stock_transceive.browse(results[0]['id']).with_context(context).find_source_move_line()
  86. def test_stock_transceive_search_by_goods_warehouse(self):
  87. """
  88. 商品收发明细表:按商品和仓库查询
  89. """
  90. self.transceive_wizard.date_start = '2016-02-01'
  91. self.transceive_wizard.goods_id = self.env.ref('goods.mouse').id
  92. self.transceive_wizard.warehouse_id = self.env.ref(
  93. 'warehouse.hd_stock').id
  94. action = self.transceive_wizard.open_report()
  95. context = action['context']
  96. stock_transceive = self.env['report.stock.transceive']
  97. results = stock_transceive.with_context(context).search_read(domain=action['domain'])
  98. self.assertEqual(len(results), 1, results)
  99. # 查看库存调拨明细
  100. stock_transceive.browse(results[0]['id']).with_context(context).find_source_move_line()
  101. def test_stock_transceive_search_read_domain(self):
  102. """
  103. 商品收发明细表:额外增加domain
  104. """
  105. self.transceive_wizard.date_start = '2016-02-01'
  106. action = self.transceive_wizard.open_report()
  107. context = action['context']
  108. stock_transceive = self.env['report.stock.transceive']
  109. # 增加一个domain 条件
  110. result1 = stock_transceive.with_context(
  111. context).search_read(domain=[('warehouse', '=', '上海仓')])
  112. # 增加一个domain 条件,domain 中用‘|’
  113. result2 = stock_transceive.with_context(context).search_read(
  114. domain=['|', ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
  115. # with self.assertRaises(UserError): # 暂时无法解析的domain条件
  116. # stock_transceive.with_context(context).search_read(
  117. # domain=[('warehouse', '<>', '上海仓')])
  118. # with self.assertRaises(UserError): # 不可识别的domain条件
  119. # stock_transceive.with_context(context).search_read(
  120. # domain=[('warehouse', '=', '上海仓', 'xxx')])
  121. # with self.assertRaises(UserError): # 不可识别的domain条件
  122. # stock_transceive.with_context(context).search_read(
  123. # domain=['warehouse', '=', '上海仓'])
  124. # 增加一个domain 条件,domain 中用'|','|'
  125. stock_transceive.with_context(context).search_read(
  126. domain=['|', '|', ('goods', '=', '键盘'), ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
  127. def test_stock_transceive_read_group(self):
  128. """
  129. 商品收发明细表: 按商品和仓库分组
  130. """
  131. self.transceive_wizard.date_start = '2016-02-01'
  132. action = self.transceive_wizard.open_report()
  133. context = action['context']
  134. stock_transceive = self.env['report.stock.transceive']
  135. stock_transceive.with_context(context).read_group(
  136. domain=[('warehouse', '=', '上海仓')],
  137. fields=['warehouse'],
  138. groupby=['warehouse', 'goods'],
  139. orderby='warehouse',
  140. )
上海开阖软件有限公司 沪ICP备12045867号-1