Skip to content

Commit c1ef07e

Browse files
committed
[MIG] delivery_carrier_multi_zip: Migration to 17.0
TT54925
1 parent a5c8296 commit c1ef07e

12 files changed

+52
-147
lines changed

delivery_carrier_multi_zip/README.rst

+3-16
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,15 @@ matching each shipping method.
3636
.. contents::
3737
:local:
3838

39-
Installation
40-
============
41-
42-
This module generates the initial ZIP interval entry from existing "ZIP
43-
from" and "ZIP to", filling one of the two interval parts with wildcard
44-
strings.
45-
4639
Configuration
4740
=============
4841

4942
To configure delivery methods with multiple ZIPs:
5043

5144
1. Go to Inventory > Configuration > Delivery > Shipping Methods
5245
2. Create or edit an existing record.
53-
3. Introduce a line for each interval of zip codes.
54-
55-
Known issues / Roadmap
56-
======================
57-
58-
- There's some code for proxying the standard values to the new
59-
intervals, for covering cases like automatisms or other modules that
60-
touch such fields, but there are still non covered cases like
61-
multiple consecutive writings creating weird ZIP interval tables.
46+
3. Set Zip Option as Ranges.
47+
4. Introduce a line for each interval of zip codes.
6248

6349
Bug Tracker
6450
===========
@@ -84,6 +70,7 @@ Contributors
8470
- \`Tecnativa <https://www.tecnativa.com>\_\_\`:
8571

8672
- Pedro M. Baeza
73+
- Víctor Martínez
8774

8875
- Philipp Zimmer
8976

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
22

33
from . import models
4-
from .hooks import post_init_hook

delivery_carrier_multi_zip/__manifest__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
{
44
"name": "Multiple ZIP intervals for the same delivery method",
5-
"version": "15.0.1.0.0",
5+
"version": "17.0.1.0.0",
66
"category": "Delivery",
77
"website": "https://github.com/OCA/delivery-carrier",
88
"author": "Tecnativa, Odoo Community Association (OCA)",
99
"license": "AGPL-3",
1010
"installable": True,
11-
"depends": ["delivery"],
11+
"depends": ["stock_delivery"],
1212
"data": ["security/ir.model.access.csv", "views/delivery_carrier_view.xml"],
13-
"post_init_hook": "post_init_hook",
1413
}

delivery_carrier_multi_zip/hooks.py

-18
This file was deleted.

delivery_carrier_multi_zip/models/delivery_carrier.py

+9-33
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,23 @@
77
class DeliveryCarrier(models.Model):
88
_inherit = "delivery.carrier"
99

10+
zip_option = fields.Selection(
11+
selection=[
12+
("prefix", "Prefixes"),
13+
("range", "Ranges"),
14+
],
15+
default="prefix",
16+
)
1017
zip_range_ids = fields.One2many(
1118
comodel_name="delivery.carrier.zip",
1219
inverse_name="carrier_id",
1320
string="ZIP codes",
1421
)
1522

16-
@api.model
17-
def _convert_zip_to_intervals(self, vals):
18-
if self.env.context.get("bypass_multi_zip"):
19-
return
20-
if vals.get("zip_from") or vals.get("zip_to"):
21-
vals.setdefault("zip_range_ids", [])
22-
vals["zip_range_ids"].append(
23-
(
24-
0,
25-
0,
26-
{
27-
"zip_from": vals.get("zip_from", "0") or "0",
28-
"zip_to": vals.get("zip_to", "z") or "z",
29-
},
30-
)
31-
)
32-
vals.pop("zip_from", False)
33-
vals.pop("zip_to", False)
34-
35-
@api.model_create_multi
36-
def create(self, vals_list):
37-
"""Intercept creation for changing ZIP values to ZIP interval."""
38-
for vals in vals_list:
39-
self._convert_zip_to_intervals(vals)
40-
return super().create(vals_list)
41-
42-
def write(self, vals):
43-
"""Intercept write for changing ZIP values to ZIP interval."""
44-
self._convert_zip_to_intervals(vals)
45-
return super().write(vals)
46-
4723
def _match_address(self, partner):
4824
"""Match as well by zip intervals if they are present."""
4925
res = super()._match_address(partner) # it has self.ensure_one()
50-
if res and self.zip_range_ids:
26+
if res and self.zip_option == "range" and self.zip_range_ids:
5127
partner_zip = partner.zip or ""
5228
res = bool(
5329
self.zip_range_ids.filtered(
@@ -71,4 +47,4 @@ class DeliveryCarrierZip(models.Model):
7147
@api.depends("zip_from", "zip_to")
7248
def _compute_name(self):
7349
for record in self:
74-
record.name = "%s - %s" % (record.zip_from, record.zip_to)
50+
record.name = f"{record.zip_from} - {record.zip_to}"

delivery_carrier_multi_zip/readme/CONFIGURE.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ To configure delivery methods with multiple ZIPs:
22

33
1. Go to Inventory \> Configuration \> Delivery \> Shipping Methods
44
2. Create or edit an existing record.
5+
3. Set Zip Option as Ranges.
56
3. Introduce a line for each interval of zip codes.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- \`Tecnativa \<<https://www.tecnativa.com>\>\_\_\`:
22
- Pedro M. Baeza
3+
- Víctor Martínez
34
- Philipp Zimmer

delivery_carrier_multi_zip/readme/INSTALL.md

-3
This file was deleted.

delivery_carrier_multi_zip/readme/ROADMAP.md

-4
This file was deleted.

delivery_carrier_multi_zip/static/description/index.html

+14-29
Original file line numberDiff line numberDiff line change
@@ -375,70 +375,55 @@ <h1 class="title">Multiple ZIP intervals for the same delivery method</h1>
375375
<p><strong>Table of contents</strong></p>
376376
<div class="contents local topic" id="contents">
377377
<ul class="simple">
378-
<li><a class="reference internal" href="#installation" id="toc-entry-1">Installation</a></li>
379-
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
380-
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li>
381-
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
382-
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
383-
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
384-
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
385-
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
378+
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
379+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
380+
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
381+
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
382+
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
383+
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
386384
</ul>
387385
</li>
388386
</ul>
389387
</div>
390-
<div class="section" id="installation">
391-
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
392-
<p>This module generates the initial ZIP interval entry from existing “ZIP
393-
from” and “ZIP to”, filling one of the two interval parts with wildcard
394-
strings.</p>
395-
</div>
396388
<div class="section" id="configuration">
397-
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
389+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
398390
<p>To configure delivery methods with multiple ZIPs:</p>
399391
<ol class="arabic simple">
400392
<li>Go to Inventory &gt; Configuration &gt; Delivery &gt; Shipping Methods</li>
401393
<li>Create or edit an existing record.</li>
394+
<li>Set Zip Option as Ranges.</li>
402395
<li>Introduce a line for each interval of zip codes.</li>
403396
</ol>
404397
</div>
405-
<div class="section" id="known-issues-roadmap">
406-
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
407-
<ul class="simple">
408-
<li>There’s some code for proxying the standard values to the new
409-
intervals, for covering cases like automatisms or other modules that
410-
touch such fields, but there are still non covered cases like
411-
multiple consecutive writings creating weird ZIP interval tables.</li>
412-
</ul>
413-
</div>
414398
<div class="section" id="bug-tracker">
415-
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
399+
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
416400
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/delivery-carrier/issues">GitHub Issues</a>.
417401
In case of trouble, please check there if your issue has already been reported.
418402
If you spotted it first, help us to smash it by providing a detailed and welcomed
419403
<a class="reference external" href="https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_carrier_multi_zip%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
420404
<p>Do not contact contributors directly about support or help with technical issues.</p>
421405
</div>
422406
<div class="section" id="credits">
423-
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
407+
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
424408
<div class="section" id="authors">
425-
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
409+
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
426410
<ul class="simple">
427411
<li>Tecnativa</li>
428412
</ul>
429413
</div>
430414
<div class="section" id="contributors">
431-
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
415+
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
432416
<ul class="simple">
433417
<li>`Tecnativa &lt;<a class="reference external" href="https://www.tecnativa.com">https://www.tecnativa.com</a>&gt;__`:<ul>
434418
<li>Pedro M. Baeza</li>
419+
<li>Víctor Martínez</li>
435420
</ul>
436421
</li>
437422
<li>Philipp Zimmer</li>
438423
</ul>
439424
</div>
440425
<div class="section" id="maintainers">
441-
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
426+
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
442427
<p>This module is maintained by the OCA.</p>
443428
<a class="reference external image-reference" href="https://odoo-community.org">
444429
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />

delivery_carrier_multi_zip/tests/test_delivery_carrier_multi_zip.py

+4-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Copyright 2022 Tecnativa - Pedro M. Baeza
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo.tests import common
54

6-
from odoo.addons.delivery_carrier_multi_zip.hooks import post_init_hook
5+
from odoo.addons.base.tests.common import BaseCommon
76

87

9-
class TestDeliveryCarrierMultiZip(common.TransactionCase):
8+
class TestDeliveryCarrierMultiZip(BaseCommon):
109
@classmethod
1110
def setUpClass(cls):
1211
super().setUpClass()
@@ -23,30 +22,11 @@ def setUpClass(cls):
2322
{
2423
"name": "Test carrier multi ZIP",
2524
"product_id": cls.product.id,
26-
"zip_from": "0001",
27-
"zip_to": "0001",
25+
"zip_option": "range",
26+
"zip_range_ids": [(0, 0, {"zip_from": "0001", "zip_to": "0001"})],
2827
}
2928
)
3029

31-
def test_delivery_multi_zip_write_create(self):
32-
self.assertEqual(len(self.carrier.zip_range_ids), 1)
33-
self.assertEqual(self.carrier.zip_range_ids.zip_from, "0001")
34-
self.assertEqual(self.carrier.zip_range_ids.zip_to, "0001")
35-
self.carrier.write({"zip_to": "0002"})
36-
self.assertEqual(len(self.carrier.zip_range_ids), 2)
37-
self.assertEqual(self.carrier.zip_range_ids[1].zip_from, "0")
38-
self.assertEqual(self.carrier.zip_range_ids[1].zip_to, "0002")
39-
40-
def test_post_init_hook(self):
41-
self.carrier.zip_range_ids.unlink()
42-
self.carrier.with_context(bypass_multi_zip=True).write({"zip_from": "0002"})
43-
post_init_hook(self.env.cr, None)
44-
self.assertEqual(len(self.carrier.zip_range_ids), 1)
45-
self.assertEqual(self.carrier.zip_range_ids.zip_from, "0002")
46-
self.assertEqual(self.carrier.zip_range_ids.zip_to, "z")
47-
self.carrier.refresh()
48-
self.assertFalse(self.carrier.zip_from)
49-
5030
def test_available_carriers(self):
5131
self.assertIn(self.carrier, self.carrier.available_carriers(self.partner_1))
5232
self.assertNotIn(self.carrier, self.carrier.available_carriers(self.partner_2))

delivery_carrier_multi_zip/views/delivery_carrier_view.xml

+18-16
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
<field name="model">delivery.carrier</field>
77
<field name="inherit_id" ref="delivery.view_delivery_carrier_form" />
88
<field name="arch" type="xml">
9-
<group name="zip_from" position="attributes">
10-
<attribute name="invisible">1</attribute>
11-
</group>
12-
<group name="zip_to" position="attributes">
13-
<attribute name="invisible">1</attribute>
14-
</group>
15-
<xpath expr="//group[@name='country_details']/.." position="after">
16-
<group name="group_zip_range_ids" colspan="2">
17-
<field name="zip_range_ids">
18-
<tree editable="bottom" default_order="zip_from, zip_to">
19-
<field name="zip_from" />
20-
<field name="zip_to" />
21-
</tree>
22-
</field>
23-
</group>
24-
</xpath>
9+
<field name="zip_prefix_ids" position="before">
10+
<field
11+
name="zip_option"
12+
widget="radio"
13+
options="{'horizontal': true}"
14+
/>
15+
</field>
16+
<field name="zip_prefix_ids" position="attributes">
17+
<attribute name="invisible">zip_option!='prefix'</attribute>
18+
</field>
19+
<field name="zip_prefix_ids" position="after">
20+
<field name="zip_range_ids" invisible="zip_option!='range'">
21+
<tree editable="bottom" default_order="zip_from, zip_to">
22+
<field name="zip_from" />
23+
<field name="zip_to" />
24+
</tree>
25+
</field>
26+
</field>
2527
</field>
2628
</record>
2729
</odoo>

0 commit comments

Comments
 (0)