Skip to content

Commit 258e6b6

Browse files
committed
Merge PR OCA#380 into 14.0
Signed-off-by simahawk
2 parents 001821f + 7fea3c9 commit 258e6b6

File tree

11 files changed

+178
-0
lines changed

11 files changed

+178
-0
lines changed

delivery_carrier_city/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

delivery_carrier_city/__manifest__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2021 Camptocamp SA - Iván Todorovich
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Delivery Carrier City",
6+
"summary": "Integrates delivery with base_address_city",
7+
"version": "14.0.1.0.0",
8+
"category": "Delivery",
9+
"website": "https://github.com/OCA/delivery-carrier",
10+
"author": "Camptocamp, Odoo Community Association (OCA)",
11+
"maintainers": ["ivantodorovich"],
12+
"license": "AGPL-3",
13+
"depends": [
14+
"delivery",
15+
"base_address_city",
16+
],
17+
"data": [
18+
"views/delivery_carrier.xml",
19+
],
20+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import delivery_carrier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Camptocamp SA - Iván Todorovich
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class DeliveryCarrier(models.Model):
8+
_inherit = "delivery.carrier"
9+
10+
city_ids = fields.Many2many(
11+
"res.city",
12+
relation="delivery_carrier_city_rel",
13+
column1="carrier_id",
14+
column2="city_id",
15+
string="Cities",
16+
)
17+
18+
def _match_address(self, partner):
19+
# Override to account for city_ids
20+
if self.city_ids and partner.city_id not in self.city_ids:
21+
return False
22+
return super()._match_address(partner)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Camptocamp <https://www.camptocamp.com>`_
2+
3+
* Iván Todorovich <ivan.todorovich@gmail.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Integrates delivery carrier with base_address_city, to allow to
2+
use cities in the delivery methods' destination conditions.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_delivery_carrier_city
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright 2021 Camptocamp SA - Iván Todorovich
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo.tests import common
5+
6+
7+
class TestDeliveryCarrierCity(common.SavepointCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
super().setUpClass()
11+
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
12+
# Countries
13+
cls.france = cls.env.ref("base.fr")
14+
# States
15+
cls.ile_de_france = cls.env["res.country.state"].create(
16+
{
17+
"name": "Île-de-France",
18+
"code": "FR-IDF",
19+
"country_id": cls.france.id,
20+
}
21+
)
22+
cls.cote_azur = cls.env["res.country.state"].create(
23+
{
24+
"name": "Provence-Alpes-Côte-d'Azur",
25+
"code": "FR-PAC",
26+
"country_id": cls.france.id,
27+
}
28+
)
29+
# Cities
30+
cls.paris = cls.env["res.city"].create(
31+
{
32+
"name": "Paris",
33+
"state_id": cls.ile_de_france.id,
34+
"country_id": cls.france.id,
35+
"zipcode": "75000",
36+
}
37+
)
38+
cls.nice = cls.env["res.city"].create(
39+
{
40+
"name": "Nice",
41+
"state_id": cls.cote_azur.id,
42+
"country_id": cls.france.id,
43+
"zipcode": "06000",
44+
}
45+
)
46+
# Disable all other delivery methods
47+
cls.env["delivery.carrier"].search([]).write({"active": False})
48+
# Create delivery methods
49+
cls.product = cls.env["product.product"].create({"name": "Delivery"})
50+
cls.carrier_paris = cls.env["delivery.carrier"].create(
51+
{
52+
"name": "Delivery in Paris",
53+
"product_id": cls.product.id,
54+
"delivery_type": "fixed",
55+
"fixed_price": 15,
56+
"sequence": 10,
57+
"country_ids": [(4, cls.france.id)],
58+
"city_ids": [(4, cls.paris.id)],
59+
}
60+
)
61+
cls.carrier_france = cls.env["delivery.carrier"].create(
62+
{
63+
"name": "Delivery in France",
64+
"product_id": cls.product.id,
65+
"delivery_type": "fixed",
66+
"fixed_price": 25,
67+
"sequence": 20,
68+
"country_ids": [(4, cls.france.id)],
69+
}
70+
)
71+
72+
def _get_available_carriers(self, partner):
73+
return self.env["delivery.carrier"].search([]).available_carriers(partner)
74+
75+
def test_00_delivery_carrier_city_match(self):
76+
# Partner living in paris
77+
partner = self.env["res.partner"].create(
78+
{
79+
"name": "Edgar Degas",
80+
"city_id": self.paris.id,
81+
"state_id": self.paris.state_id.id,
82+
"country_id": self.paris.country_id.id,
83+
}
84+
)
85+
# Check available carriers
86+
carriers = self._get_available_carriers(partner)
87+
self.assertIn(self.carrier_france, carriers)
88+
self.assertIn(self.carrier_paris, carriers)
89+
90+
def test_01_delivery_carrier_city_not_match(self):
91+
# Partner not living in paris
92+
partner = self.env["res.partner"].create(
93+
{
94+
"name": "Henri Matisse",
95+
"city_id": self.nice.id,
96+
"state_id": self.nice.state_id.id,
97+
"country_id": self.nice.country_id.id,
98+
}
99+
)
100+
# Check available carriers
101+
carriers = self._get_available_carriers(partner)
102+
self.assertIn(self.carrier_france, carriers)
103+
self.assertNotIn(self.carrier_paris, carriers)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
Copyright 2021 Camptocamp SA - Iván Todorovich
4+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
-->
6+
<odoo>
7+
8+
<record id="view_delivery_carrier_form" model="ir.ui.view">
9+
<field name="model">delivery.carrier</field>
10+
<field name="inherit_id" ref="delivery.view_delivery_carrier_form" />
11+
<field name="arch" type="xml">
12+
<field name="state_ids" position="after">
13+
<field name="city_ids" widget="many2many_tags" />
14+
</field>
15+
</field>
16+
</record>
17+
18+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../delivery_carrier_city

setup/delivery_carrier_city/setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)