|
- from odoo.tests.common import TransactionCase
- from odoo.exceptions import UserError
- import operator
-
-
- class TestReport(TransactionCase):
- def setUp(self):
- super(TestReport, self).setUp()
-
- self.env.ref('core.goods_category_1').account_id = self.env.ref(
- 'finance.account_goods').id
- self.env.ref('warehouse.wh_in_whin0').date = '2016-02-06'
- self.env.ref('warehouse.wh_in_whin3').date = '2016-02-06'
- self.env.ref('warehouse.wh_in_whin1').date = '2016-02-06'
- self.env.ref('warehouse.wh_in_wh_in_attribute').date = '2016-02-06'
-
-
-
-
-
-
-
-
-
- self.env['wh.in'].search(
- [('name', '!=', 'WH/IN/16040004')]).approve_order()
-
- warehouse_obj = self.env.ref('warehouse.wh_in_whin0')
-
-
- self.env['wh.internal'].search([]).approve_order()
-
- ''' odoo13 必须在这里read一下后面sql才能取到数据 '''
- for l in self.env['wh.move.line'].search([]):
- l.read()
-
- self.transceive_wizard = self.env['report.stock.transceive.wizard'].create({
- 'date_start': '2016-04-01',
- 'date_end': '2016-04-03'})
-
- def test_report_base(self):
- report_base = self.env['report.base'].create({})
-
- self.assertEqual(report_base.select_sql(), '')
- self.assertEqual(report_base.from_sql(), '')
- self.assertEqual(report_base.where_sql(), '')
- self.assertEqual(report_base.group_sql(), '')
- self.assertEqual(report_base.order_sql(), '')
- self.assertEqual(report_base.get_context(), {})
- self.assertEqual(report_base.collect_data_by_sql(), [])
-
- def test_open_report(self):
-
- self.assertEqual(self.transceive_wizard.onchange_date(), {})
-
- self.transceive_wizard.date_end = '1999-09-09'
- results = self.transceive_wizard.onchange_date()
- real_results = {'warning': {
- 'title': '错误',
- 'message': '结束日期不可以小于开始日期'
- }, 'value': {'date_end': self.transceive_wizard.date_start}}
-
- self.assertEqual(results, real_results)
- self.assertEqual(self.transceive_wizard.open_report().get(
- 'res_model'), 'report.stock.transceive')
-
- self.env['report.stock.transceive.wizard'].create({})
-
- def test_stock_transceive_search_read(self):
- stock_transceive = self.env['report.stock.transceive'].create({})
- self.transceive_wizard.date_start = '2016-02-01'
- context = self.transceive_wizard.open_report().get('context')
-
- real_results = [
-
- ('键盘', '总仓', 0, 600),
- ('鼠标', '总仓', 0, 2),
- ('网线', '总仓', 0, 12048),
-
- ('键鼠套装', '总仓', 0, 96),
- ]
- results = stock_transceive.with_context(context).search_read(domain=[])
- length = stock_transceive.with_context(context).search_count(domain=[])
- self.assertEqual(len(results), len(real_results))
- self.assertEqual(len(results), length)
-
- instance = stock_transceive.with_context(
- context).browse(results[0].get('id'))
- self.assertEqual(instance.read(['warehouse'])[0].get(
- 'warehouse'), results[0].get('warehouse'))
-
- for result in results:
- result = (
- result.get('goods'),
- result.get('warehouse'),
- result.get('goods_qty_out'),
- result.get('goods_qty_in'),
- )
- self.assertTrue(result in real_results)
-
- stock_transceive.with_context(context).find_source_move_line()
-
- def test_stock_transceive_search_by_goods_warehouse(self):
- """
- 商品收发明细表:按商品和仓库查询
- """
- self.transceive_wizard.date_start = '2016-02-01'
- self.transceive_wizard.goods_id = self.env.ref('goods.mouse').id
- self.transceive_wizard.warehouse_id = self.env.ref(
- 'warehouse.hd_stock').id
- context = self.transceive_wizard.open_report().get('context')
- stock_transceive = self.env['report.stock.transceive'].create({})
- results = stock_transceive.with_context(context).search_read(domain=[])
- self.assertEqual(len(results), 1)
-
- stock_transceive.with_context(context).find_source_move_line()
-
- def test_stock_transceive_search_read_domain(self):
- """
- 商品收发明细表:额外增加domain
- """
- self.transceive_wizard.date_start = '2016-02-01'
- context = self.transceive_wizard.open_report().get('context')
- stock_transceive = self.env['report.stock.transceive'].create({})
-
- result1 = stock_transceive.with_context(
- context).search_read(domain=[('warehouse', '=', '上海仓')])
-
- result2 = stock_transceive.with_context(context).search_read(
- domain=['|', ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
-
-
-
-
-
-
-
-
-
-
- stock_transceive.with_context(context).search_read(
- domain=['|', '|', ('goods', '=', '键盘'), ('warehouse', '=', '上海仓'), ('warehouse', '=', '总仓')])
-
- def test_stock_transceive_read_group(self):
- """
- 商品收发明细表: 按商品和仓库分组
- """
- self.transceive_wizard.date_start = '2016-02-01'
- context = self.transceive_wizard.open_report().get('context')
- stock_transceive = self.env['report.stock.transceive'].create({})
- stock_transceive.with_context(context).read_group(
- domain=[('warehouse', '=', '上海仓')],
- fields=['warehouse'],
- groupby=['warehouse', 'goods'],
- orderby='warehouse',
- )
|