| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import odoo |
| 5 |
from odoo import fields |
| 6 |
from odoo.addons.point_of_sale.tests.common import TestPoSCommon |
| 7 |
from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon |
| 8 |
|
| 9 |
|
| 10 |
@odoo.tests.tagged('post_install', '-at_install') |
| 11 |
class TestPoSSaleReport(TestPoSCommon, TestPointOfSaleHttpCommon): |
| 12 |
|
| 13 |
def setUp(self): |
| 14 |
super(TestPoSSaleReport, self).setUp() |
| 15 |
self.config = self.basic_config |
| 16 |
self.product0 = self.create_product('Product 0', self.categ_basic, 0.0, 0.0) |
| 17 |
self.partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'}) |
| 18 |
|
| 19 |
|
| 20 |
self.uom_reference = self.env['uom.uom'].create({ |
| 21 |
'name': 'Reference Unit', |
| 22 |
'relative_factor': 1, |
| 23 |
}) |
| 24 |
self.uom_dozen = self.env['uom.uom'].create({ |
| 25 |
'name': 'Dozen', |
| 26 |
'relative_factor': 12, |
| 27 |
'relative_uom_id': self.uom_reference.id, |
| 28 |
}) |
| 29 |
self.product0.uom_id = self.uom_dozen |
| 30 |
|
| 31 |
def test_weight_and_volume(self): |
| 32 |
self.product0.product_tmpl_id.weight = 3 |
| 33 |
self.product0.product_tmpl_id.volume = 4 |
| 34 |
|
| 35 |
self.open_new_session() |
| 36 |
session = self.pos_session |
| 37 |
orders = [] |
| 38 |
|
| 39 |
|
| 40 |
orders.append(self.create_ui_order_data([(self.product0, 3)])) |
| 41 |
orders.append(self.create_ui_order_data([(self.product0, 1)])) |
| 42 |
self.env['pos.order'].sync_from_ui(orders) |
| 43 |
|
| 44 |
session.order_ids[0].lines.copy() |
| 45 |
|
| 46 |
session.action_pos_session_closing_control() |
| 47 |
|
| 48 |
|
| 49 |
reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id', limit=2) |
| 50 |
self.assertEqual(reports[0].weight, 3) |
| 51 |
self.assertEqual(reports[0].volume, 4) |
| 52 |
self.assertEqual(reports[1].weight, 18) |
| 53 |
self.assertEqual(reports[1].volume, 24) |
| 54 |
|
| 55 |
def test_refund_line_report_prices_sign(self): |
| 56 |
test_product = self.env['product.product'].create({ |
| 57 |
'name': 'Test Product', |
| 58 |
'list_price': 10.00, |
| 59 |
'taxes_id': False, |
| 60 |
'available_in_pos': True, |
| 61 |
}) |
| 62 |
self.main_pos_config.with_user(self.pos_user).open_ui() |
| 63 |
current_session = self.main_pos_config.current_session_id |
| 64 |
|
| 65 |
self.start_tour("/pos/ui/%d" % self.main_pos_config.id, 'refund_multiple_products_amounts_compliance', login="pos_user") |
| 66 |
|
| 67 |
total_cash_payment = sum(current_session.mapped('order_ids.payment_ids').filtered( |
| 68 |
lambda payment: payment.payment_method_id.type == 'cash').mapped('amount') |
| 69 |
) |
| 70 |
current_session.post_closing_cash_details(total_cash_payment) |
| 71 |
current_session.close_session_from_ui() |
| 72 |
self.assertEqual(current_session.state, 'closed') |
| 73 |
|
| 74 |
report = self.env['sale.report'].sudo().search([('product_id', '=', test_product.id), ('name', 'ilike', '% REFUND')], order='id', limit=1) |
| 75 |
self.assertEqual(report.product_uom_qty, -2) |
| 76 |
self.assertEqual(report.price_subtotal, report.product_uom_qty * test_product.list_price) |
| 77 |
self.assertEqual(report.price_total, report.price_subtotal) |
| 78 |
|
| 79 |
def test_weight_and_volume_product_variant(self): |
| 80 |
colors = ['red', 'blue'] |
| 81 |
prod_attr = self.env['product.attribute'].create({'name': 'Color', 'create_variant': 'dynamic'}) |
| 82 |
prod_attr_values = self.env['product.attribute.value'].create([{'name': color, 'attribute_id': prod_attr.id, 'sequence': 1} for color in colors]) |
| 83 |
|
| 84 |
uom_unit = self.env.ref('uom.product_uom_unit') |
| 85 |
product_template = self.env['product.template'].create({ |
| 86 |
'name': 'Sofa', |
| 87 |
'uom_id': uom_unit.id, |
| 88 |
'attribute_line_ids': [(0, 0, { |
| 89 |
'attribute_id': prod_attr.id, |
| 90 |
'value_ids': [(6, 0, prod_attr_values.ids)] |
| 91 |
})] |
| 92 |
}) |
| 93 |
prod_tmpl_attrs = self.env['product.template.attribute.value'].search([ |
| 94 |
('attribute_line_id', '=', product_template.attribute_line_ids.id), |
| 95 |
('product_attribute_value_id', 'in', prod_attr_values.ids) |
| 96 |
]) |
| 97 |
|
| 98 |
product_1 = product_template._create_product_variant(prod_tmpl_attrs[0]) |
| 99 |
product_1.weight = 1 |
| 100 |
product_1.volume = 1 |
| 101 |
|
| 102 |
product_2 = product_template._create_product_variant(prod_tmpl_attrs[1]) |
| 103 |
product_2.weight = 2 |
| 104 |
product_2.volume = 2 |
| 105 |
|
| 106 |
self.open_new_session() |
| 107 |
session = self.pos_session |
| 108 |
|
| 109 |
order = self.create_ui_order_data([(product_1, 3), (product_2, 3)]) |
| 110 |
self.env['pos.order'].sync_from_ui([order]) |
| 111 |
|
| 112 |
session.action_pos_session_closing_control() |
| 113 |
|
| 114 |
report = self.env['sale.report'].sudo().search([('product_id', '=', product_1.id)], order='id', limit=1) |
| 115 |
self.assertEqual(report.weight, 3) |
| 116 |
self.assertEqual(report.weight, 3) |
| 117 |
report = self.env['sale.report'].sudo().search([('product_id', '=', product_2.id)], order='id', limit=1) |
| 118 |
self.assertEqual(report.weight, 6) |
| 119 |
self.assertEqual(report.weight, 6) |
| 120 |
|
| 121 |
def test_different_shipping_address(self): |
| 122 |
product_0 = self.create_product('Product 0', self.categ_basic, 0.0, 0.0) |
| 123 |
sale_order = self.env['sale.order'].sudo().create({ |
| 124 |
'partner_id': self.customer.id, |
| 125 |
'partner_shipping_id': self.other_customer.id, |
| 126 |
'order_line': [(0, 0, { |
| 127 |
'product_id': product_0.id, |
| 128 |
})], |
| 129 |
}) |
| 130 |
self.open_new_session() |
| 131 |
|
| 132 |
data = self.create_ui_order_data([(product_0, 1)], {}, self.customer, True) |
| 133 |
data['lines'][0][2]['sale_order_origin_id'] = sale_order.id |
| 134 |
data['lines'][0][2]['sale_order_line_id'] = sale_order.order_line[0].id |
| 135 |
order_ids = self.env['pos.order'].sync_from_ui([data]) |
| 136 |
|
| 137 |
move_id = self.env['account.move'].browse(order_ids['pos.order'][0]['account_move']) |
| 138 |
self.assertEqual(move_id.partner_id.id, self.customer.id) |
| 139 |
self.assertEqual(move_id.partner_shipping_id.id, self.other_customer.id) |
| 140 |
|
| 141 |
def test_warehouse(self): |
| 142 |
|
| 143 |
self.open_new_session() |
| 144 |
session = self.pos_session |
| 145 |
orders = [] |
| 146 |
|
| 147 |
|
| 148 |
orders.append(self.create_ui_order_data([(self.product0, 3)])) |
| 149 |
self.env['pos.order'].sync_from_ui(orders) |
| 150 |
|
| 151 |
session.action_pos_session_closing_control() |
| 152 |
|
| 153 |
reports = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id', limit=2) |
| 154 |
self.assertEqual(reports[0].warehouse_id.id, self.config.picking_type_id.warehouse_id.id) |
| 155 |
|
| 156 |
def test_qty_deliverd_qty_to_deliver_in_sales_report(self): |
| 157 |
""" |
| 158 |
Track the quantity of products ordered based on their picking state. for example : If an order is created for 3 products |
| 159 |
with the option to ship later, the products will be listed under qty_to_deliver in the sales report until the picking state |
| 160 |
is validated. Once validated and marked as done, the quantity will shift to qty_delivered. |
| 161 |
""" |
| 162 |
self.config.ship_later = True |
| 163 |
self.open_new_session() |
| 164 |
session = self.pos_session |
| 165 |
|
| 166 |
orders = [] |
| 167 |
|
| 168 |
orders.append(self.create_ui_order_data([(self.product0, 5, 100), (self.product0, 3)], {}, self.partner_1)) |
| 169 |
orders[0]['shipping_date'] = fields.Date.to_string(fields.Date.today()) |
| 170 |
|
| 171 |
order = self.env['pos.order'].sync_from_ui(orders) |
| 172 |
order = self.env['pos.order'].browse(order['pos.order'][0]['id']) |
| 173 |
|
| 174 |
session.action_pos_session_closing_control() |
| 175 |
|
| 176 |
report = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id') |
| 177 |
|
| 178 |
self.assertEqual(sum(report.mapped('qty_to_deliver')), 8) |
| 179 |
self.assertEqual(sum(report.mapped('qty_delivered')), 0) |
| 180 |
|
| 181 |
order.picking_ids.move_ids.quantity = 8.0 |
| 182 |
order.picking_ids.button_validate() |
| 183 |
|
| 184 |
self.env.flush_all() |
| 185 |
self.env.clear() |
| 186 |
|
| 187 |
report = self.env['sale.report'].sudo().search([('product_id', '=', self.product0.id)], order='id') |
| 188 |
|
| 189 |
self.assertEqual(sum(report.mapped('qty_to_deliver')), 0) |
| 190 |
self.assertEqual(sum(report.mapped('qty_delivered')), 8) |