| 1 |
|
| 2 |
|
| 3 |
from unittest.mock import patch |
| 4 |
|
| 5 |
from odoo import Command |
| 6 |
from odoo.exceptions import ValidationError |
| 7 |
from odoo.tests import Form, tagged |
| 8 |
|
| 9 |
from odoo.addons.website_sale.tests.common import MockRequest |
| 10 |
from odoo.addons.website_sale_collect.tests.common import ClickAndCollectCommon |
| 11 |
from odoo.addons.website_sale_stock.tests.common import WebsiteSaleStockCommon |
| 12 |
|
| 13 |
|
| 14 |
@tagged('post_install', '-at_install') |
| 15 |
class TestDeliveryCarrier(ClickAndCollectCommon, WebsiteSaleStockCommon): |
| 16 |
|
| 17 |
def test_prevent_publishing_when_no_warehouse(self): |
| 18 |
self.in_store_dm.is_published = False |
| 19 |
self.in_store_dm.warehouse_ids = [Command.clear()] |
| 20 |
with self.assertRaises(ValidationError): |
| 21 |
self.in_store_dm.is_published = True |
| 22 |
|
| 23 |
def test_same_company_for_delivery_method_and_warehouse(self): |
| 24 |
self.in_store_dm.company_id = self.company_id |
| 25 |
self.companyA = self.env['res.company'].create({'name': 'Company A'}) |
| 26 |
self.warehouse_2 = self._create_warehouse(company_id=self.companyA.id) |
| 27 |
with self.assertRaises(ValidationError): |
| 28 |
self.in_store_dm.warehouse_ids = [Command.set([self.warehouse_2.id])] |
| 29 |
|
| 30 |
def test_creating_in_store_delivery_method_sets_integration_level_to_rate(self): |
| 31 |
new_in_store_carrier = self.env['delivery.carrier'].create({ |
| 32 |
'name': "Test Carrier", |
| 33 |
'delivery_type': 'in_store', |
| 34 |
'product_id': self.dm_product.id, |
| 35 |
}) |
| 36 |
self.assertEqual(new_in_store_carrier.integration_level, 'rate') |
| 37 |
|
| 38 |
def test_in_store_get_close_locations_returned_data(self): |
| 39 |
so = self._create_in_store_delivery_order() |
| 40 |
|
| 41 |
wh_address_partner = self.env['res.partner'].create({ |
| 42 |
**self.dummy_partner_address_values, |
| 43 |
'name': "Shop 1", |
| 44 |
'partner_latitude': 1.0, |
| 45 |
'partner_longitude': 2.0, |
| 46 |
}) |
| 47 |
self.warehouse.partner_id = wh_address_partner.id |
| 48 |
self.warehouse.opening_hours = self.env['resource.calendar'].create({ |
| 49 |
'name': 'Opening hours', |
| 50 |
'attendance_ids': [ |
| 51 |
Command.create({ |
| 52 |
'name': 'Monday Morning', |
| 53 |
'dayofweek': '0', |
| 54 |
'hour_from': 8, |
| 55 |
'hour_to': 12, |
| 56 |
'day_period': 'morning', |
| 57 |
}), |
| 58 |
Command.create({ |
| 59 |
'name': 'Monday Lunch', |
| 60 |
'dayofweek': '0', |
| 61 |
'hour_from': 12, |
| 62 |
'hour_to': 13, |
| 63 |
'day_period': 'lunch', |
| 64 |
}), |
| 65 |
Command.create({ |
| 66 |
'name': 'Monday Afternoon', |
| 67 |
'dayofweek': '0', |
| 68 |
'hour_from': 13, |
| 69 |
'hour_to': 17, |
| 70 |
'day_period': 'afternoon', |
| 71 |
}), |
| 72 |
], |
| 73 |
}) |
| 74 |
|
| 75 |
with patch( |
| 76 |
'odoo.addons.base_geolocalize.models.res_partner.ResPartner.geo_localize', |
| 77 |
return_value=True |
| 78 |
), MockRequest(self.env, website=self.website, sale_order_id=so.id): |
| 79 |
locations = self.in_store_dm._in_store_get_close_locations(wh_address_partner) |
| 80 |
self.assertEqual( |
| 81 |
locations, [{ |
| 82 |
'id': self.warehouse.id, |
| 83 |
'name': wh_address_partner['name'].title(), |
| 84 |
'street': wh_address_partner['street'].title(), |
| 85 |
'city': wh_address_partner.city.title(), |
| 86 |
'zip_code': wh_address_partner.zip, |
| 87 |
'state': wh_address_partner.state_id.code, |
| 88 |
'country_code': wh_address_partner.country_code, |
| 89 |
'latitude': wh_address_partner.partner_latitude, |
| 90 |
'longitude': wh_address_partner.partner_longitude, |
| 91 |
'additional_data': {'in_store_stock_data': {'in_stock': True}}, |
| 92 |
'opening_hours': { |
| 93 |
'0': ['08:00 - 12:00', '13:00 - 17:00'], |
| 94 |
'1': [], |
| 95 |
'2': [], |
| 96 |
'3': [], |
| 97 |
'4': [], |
| 98 |
'5': [], |
| 99 |
'6': [], |
| 100 |
}, |
| 101 |
'distance': 0.0, |
| 102 |
}] |
| 103 |
) |