GoodERP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
7.1KB

  1. from odoo.tests.common import TransactionCase
  2. from odoo.exceptions import UserError
  3. import time
  4. import logging
  5. _logger = logging.getLogger(__name__)
  6. class TestGoods(TransactionCase):
  7. ''' 测试和仓库相关的商品的有关逻辑 '''
  8. def setUp(self):
  9. super(TestGoods, self).setUp()
  10. self.env.ref('core.goods_category_1').account_id = self.env.ref(
  11. 'finance.account_goods').id
  12. self.env.ref('warehouse.wh_in_whin1').date = '2016-02-06'
  13. self.env.ref('warehouse.wh_in_whin3').date = '2016-02-06'
  14. # 总部仓库
  15. self.hd_warehouse = self.browse_ref('warehouse.hd_stock')
  16. self.others_in = self.browse_ref('warehouse.wh_in_whin1')
  17. self.others_in_cable = self.browse_ref('warehouse.wh_move_line_15')
  18. self.others_in_keyboard_mouse = self.browse_ref(
  19. 'warehouse.wh_move_line_16')
  20. self.others_in_cable.cost = self.others_in_cable.cost_unit * self.others_in_cable.goods_qty
  21. self.others_in_keyboard_mouse.cost = self.others_in_keyboard_mouse.cost_unit * self.others_in_keyboard_mouse.goods_qty
  22. self.others_in_2 = self.browse_ref('warehouse.wh_in_whin3')
  23. self.others_in_2_keyboard_mouse = self.browse_ref(
  24. 'warehouse.wh_move_line_keyboard_mouse_in_2')
  25. self.others_in_2_keyboard_mouse.cost = self.others_in_2_keyboard_mouse.cost_unit * self.others_in_2_keyboard_mouse.goods_qty
  26. self.goods_keyboard_mouse = self.browse_ref('goods.keyboard_mouse')
  27. self.goods_cable = self.browse_ref('goods.cable')
  28. self.goods_iphone = self.browse_ref('goods.iphone')
  29. # 将网线和键盘套装入库
  30. self.others_in.approve_order()
  31. time.sleep(2)
  32. self.others_in_2.approve_order()
  33. # 有属性商品iphone黑色和白色入库
  34. self.others_in_attr = self.browse_ref('warehouse.wh_in_wh_in_attribute')
  35. self.others_in_attr.approve_order()
  36. ''' odoo13 必须在这里read一下后面sql才能取到数据 '''
  37. for _l in self.env['wh.move.line'].search([('state', '=', 'done')]):
  38. _logger.info('%s %s +%s' % (
  39. _l.goods_id.name, _l.warehouse_dest_id.name, _l.goods_qty))
  40. def test_stock(self):
  41. keyboard_mouse_results = self.goods_keyboard_mouse.get_stock_qty()
  42. cable_results = self.goods_cable.get_stock_qty()
  43. real_keyboard_mouse_results = {
  44. 'warehouse': '总仓',
  45. 'qty': self.others_in_keyboard_mouse.goods_qty + self.others_in_2_keyboard_mouse.goods_qty,
  46. }
  47. real_cable_results = {
  48. 'warehouse': '总仓',
  49. 'qty': self.others_in_cable.goods_qty,
  50. }
  51. self.assertEqual(real_keyboard_mouse_results,
  52. keyboard_mouse_results[0])
  53. self.assertEqual(real_cable_results, cable_results[0])
  54. def test_cost(self):
  55. # 使用_get_cost来获取最后一次历史成本
  56. cost = self.goods_cable._get_cost(self.hd_warehouse)
  57. # 应该等于最后一次入库的成本
  58. self.assertEqual(cost, self.others_in_cable.cost_unit)
  59. # 忽略掉最后一次入库的行为,此时成本应该去商品的默认成本
  60. cost = self.goods_cable._get_cost(
  61. self.hd_warehouse, ignore=self.others_in_cable.id)
  62. self.assertEqual(cost, self.goods_cable.cost)
  63. # 使用_get_cost来获取最后一次历史成本
  64. cost = self.goods_keyboard_mouse._get_cost(self.hd_warehouse)
  65. self.assertEqual(cost, self.others_in_2_keyboard_mouse.cost_unit)
  66. # 忽略掉最后一次入库的成本,所以等于上一次入库的成本
  67. cost = self.goods_keyboard_mouse._get_cost(
  68. self.hd_warehouse, ignore=self.others_in_2_keyboard_mouse.id)
  69. self.assertEqual(cost, self.others_in_keyboard_mouse.cost_unit)
  70. # 使用FIFO来获取成本的函数
  71. # 48 * 120的键盘套装先入库,48 * 80的键盘套装后入库
  72. suggested_cost_func = self.goods_keyboard_mouse.get_suggested_cost_by_warehouse
  73. suggested_cost, _ = suggested_cost_func(self.hd_warehouse, 96)
  74. self.assertEqual(suggested_cost, 48 * 120 + 48 * 80)
  75. suggested_cost, _ = suggested_cost_func(self.hd_warehouse, 72)
  76. self.assertEqual(suggested_cost, 48 * 120 + 24 * 80)
  77. suggested_cost, _ = suggested_cost_func(self.hd_warehouse, 48)
  78. self.assertEqual(suggested_cost, 48 * 120)
  79. suggested_cost, _ = suggested_cost_func(self.hd_warehouse, 24)
  80. self.assertEqual(suggested_cost, 24 * 120)
  81. # 忽略掉第一次48 * 120入库的行为,所以获取到的单位成本永远是80
  82. suggested_cost, _ = suggested_cost_func(
  83. self.hd_warehouse, 96, ignore_move=self.others_in_keyboard_mouse.id)
  84. self.assertEqual(suggested_cost, 96 * 80)
  85. suggested_cost, _ = suggested_cost_func(
  86. self.hd_warehouse, 72, ignore_move=self.others_in_keyboard_mouse.id)
  87. self.assertEqual(suggested_cost, 72 * 80)
  88. suggested_cost, _ = suggested_cost_func(
  89. self.hd_warehouse, 48, ignore_move=self.others_in_keyboard_mouse.id)
  90. self.assertEqual(suggested_cost, 48 * 80)
  91. suggested_cost, _ = suggested_cost_func(
  92. self.hd_warehouse, 24, ignore_move=self.others_in_keyboard_mouse.id)
  93. self.assertEqual(suggested_cost, 24 * 80)
  94. def test_get_matching_records_with_attribute(self):
  95. '''获取匹配记录(缺货向导确认时)'''
  96. # 有属性商品获取匹配记录 12 * 4888 的iphone 白、12 * 5000 的iphone 黑入库
  97. others_in = self.others_in.copy()
  98. line = self.env['wh.move.line'].create({
  99. 'move_id': others_in.move_id.id,
  100. 'goods_id': self.goods_iphone.id,
  101. 'attribute_id': self.env.ref('goods.iphone_white').id,
  102. 'goods_qty': 1,
  103. 'uom_id': self.goods_iphone.uom_id.id,
  104. 'type': 'in',
  105. 'state': 'done'})
  106. suggested_cost, _ = self.goods_iphone.with_context({
  107. 'wh_in_line_ids': [line.id]}).get_suggested_cost_by_warehouse(
  108. self.hd_warehouse, qty=13, attribute=self.env.ref('goods.iphone_white'))
  109. def test_compute_stock_qty(self):
  110. self.assertEqual(self.goods_cable.current_qty, 48)
  111. def test_write(self):
  112. """商品有库存,不允许修改单位或转化率"""
  113. with self.assertRaises(UserError):
  114. self.goods_cable.uos_id = self.env.ref('core.uom_pc').id
  115. with self.assertRaises(UserError):
  116. self.goods_cable.conversion = 3
  117. def test_get_matching_records_has_location(self):
  118. '''获取匹配记录(出库单行填写了库位)'''
  119. # 已有键鼠套装入库到总仓的a库位
  120. wh_out = self.env.ref('warehouse.wh_out_whout1')
  121. wh_out.line_out_ids[0].location_id = self.env.ref('warehouse.a001_location')
  122. wh_out.approve_order()
  123. class TestResCompany(TransactionCase):
  124. def test_get_operating_cost_account_id(self):
  125. ''' 测试默认生产费用科目 '''
  126. self.env['res.company'].create({
  127. 'name': 'demo company',
  128. 'partner_id': self.env.ref('core.zt').id
  129. })
上海开阖软件有限公司 沪ICP备12045867号-1