test_pos_sale_report.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo
  4. from odoo.addons.point_of_sale.tests.common import TestPoSCommon
  5. @odoo.tests.tagged('post_install', '-at_install')
  6. class TestPoSSaleReport(TestPoSCommon):
  7. def setUp(self):
  8. super(TestPoSSaleReport, self).setUp()
  9. self.config = self.basic_config
  10. self.product0 = self.create_product('Product 0', self.categ_basic, 0.0, 0.0)
  11. def test_weight_and_volume(self):
  12. self.product0.product_tmpl_id.weight = 3
  13. self.product0.product_tmpl_id.volume = 4
  14. self.open_new_session()
  15. session = self.pos_session
  16. orders = []
  17. # Process two orders
  18. orders.append(self.create_ui_order_data([(self.product0, 3)]))
  19. orders.append(self.create_ui_order_data([(self.product0, 1)]))
  20. self.env['pos.order'].create_from_ui(orders)
  21. # Duplicate the first line of the first order
  22. session.order_ids[0].lines.copy()
  23. session.action_pos_session_closing_control()
  24. # PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order
  25. reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id', limit=2)
  26. self.assertEqual(reports[0].weight, 3)
  27. self.assertEqual(reports[0].volume, 4)
  28. self.assertEqual(reports[1].weight, 18)
  29. self.assertEqual(reports[1].volume, 24)
  30. def test_weight_and_volume_product_variant(self):
  31. colors = ['red', 'blue']
  32. prod_attr = self.env['product.attribute'].create({'name': 'Color', 'create_variant': 'dynamic'})
  33. prod_attr_values = self.env['product.attribute.value'].create([{'name': color, 'attribute_id': prod_attr.id, 'sequence': 1} for color in colors])
  34. uom_unit = self.env.ref('uom.product_uom_unit')
  35. product_template = self.env['product.template'].create({
  36. 'name': 'Sofa',
  37. 'uom_id': uom_unit.id,
  38. 'uom_po_id': uom_unit.id,
  39. 'attribute_line_ids': [(0, 0, {
  40. 'attribute_id': prod_attr.id,
  41. 'value_ids': [(6, 0, prod_attr_values.ids)]
  42. })]
  43. })
  44. prod_tmpl_attrs = self.env['product.template.attribute.value'].search([
  45. ('attribute_line_id', '=', product_template.attribute_line_ids.id),
  46. ('product_attribute_value_id', 'in', prod_attr_values.ids)
  47. ])
  48. product_1 = product_template._create_product_variant(prod_tmpl_attrs[0])
  49. product_1.weight = 1
  50. product_1.volume = 1
  51. product_2 = product_template._create_product_variant(prod_tmpl_attrs[1])
  52. product_2.weight = 2
  53. product_2.volume = 2
  54. self.open_new_session()
  55. session = self.pos_session
  56. order = self.create_ui_order_data([(product_1, 3), (product_2, 3)])
  57. self.env['pos.order'].create_from_ui([order])
  58. session.action_pos_session_closing_control()
  59. report = self.env['sale.report'].sudo().search([('product_id', '=', product_1.id)], order='id', limit=1)
  60. self.assertEqual(report.weight, 3)
  61. self.assertEqual(report.weight, 3)
  62. report = self.env['sale.report'].sudo().search([('product_id', '=', product_2.id)], order='id', limit=1)
  63. self.assertEqual(report.weight, 6)
  64. self.assertEqual(report.weight, 6)
  65. def test_different_shipping_address(self):
  66. product_0 = self.create_product('Product 0', self.categ_basic, 0.0, 0.0)
  67. sale_order = self.env['sale.order'].create({
  68. 'partner_id': self.env.ref('base.res_partner_1').id,
  69. 'partner_shipping_id': self.env.ref('base.res_partner_2').id,
  70. 'order_line': [(0, 0, {
  71. 'product_id': product_0.id,
  72. })],
  73. })
  74. self.open_new_session()
  75. data = self.create_ui_order_data([(product_0, 1)], self.env.ref('base.res_partner_1'), True)
  76. data['data']['lines'][0][2]['sale_order_origin_id'] = sale_order.read()[0]
  77. data['data']['lines'][0][2]['sale_order_line_id'] = sale_order.order_line[0].read()[0]
  78. order_ids = self.env['pos.order'].create_from_ui([data])
  79. move_id = self.env['account.move'].browse(order_ids[0]['account_move'])
  80. self.assertEqual(move_id.partner_id.id, self.env.ref('base.res_partner_1').id)
  81. self.assertEqual(move_id.partner_shipping_id.id, self.env.ref('base.res_partner_2').id)