forked from OCA/delivery-carrier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] delivery_carrier_multi_zip: Multiple ZIP intervals for the same…
… delivery method This module allows to set more than one interval of zip codes for matching each shipping method. TT35326 [UPD] Update delivery_carrier_multi_zip.pot delivery_carrier_multi_zip 13.0.1.0.1 Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: delivery-carrier-13.0/delivery-carrier-13.0-delivery_carrier_multi_zip Translate-URL: https://translation.odoo-community.org/projects/delivery-carrier-13-0/delivery-carrier-13-0-delivery_carrier_multi_zip/
- Loading branch information
1 parent
c985813
commit 4a62022
Showing
19 changed files
with
939 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
=================================================== | ||
Multiple ZIP intervals for the same delivery method | ||
=================================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github | ||
:target: https://github.com/OCA/delivery-carrier/tree/13.0/delivery_carrier_multi_zip | ||
:alt: OCA/delivery-carrier | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/delivery-carrier-13-0/delivery-carrier-13-0-delivery_carrier_multi_zip | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/99/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to set more than one interval of zip codes for matching each | ||
shipping method. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
This module generates the initial ZIP interval entry from existing "ZIP from" | ||
and "ZIP to", filling one of the two interval parts with wildcard strings. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure delivery methods with multiple ZIPs: | ||
|
||
#. Go to Inventory > Configuration > Delivery > Shipping Methods | ||
#. Create or edit an existing record. | ||
#. Introduce a line for each interval of zip codes. | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
- There's some code for proxying the standard values to the new intervals, for | ||
covering cases like automatisms or other modules that touch such fields, but | ||
there are still non covered cases like multiple consecutive writings creating | ||
weird ZIP interval tables. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/delivery-carrier/issues/new?body=module:%20delivery_carrier_multi_zip%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>__`: | ||
|
||
* Pedro M. Baeza | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/13.0/delivery_carrier_multi_zip>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2022 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Multiple ZIP intervals for the same delivery method", | ||
"version": "13.0.1.0.1", | ||
"category": "Delivery", | ||
"website": "https://github.com/OCA/delivery-carrier", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": ["delivery"], | ||
"data": ["security/ir.model.access.csv", "views/delivery_carrier_view.xml"], | ||
"post_init_hook": "post_init_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import SUPERUSER_ID, api | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
"""Convert current ZIP field values to ZIP entries""" | ||
env = api.Environment(cr, SUPERUSER_ID, dict()) | ||
carriers = ( | ||
env["delivery.carrier"] | ||
.with_context( | ||
show_children_carriers=True # compatibility with delivery_multi_destination | ||
) | ||
.search(["|", ("zip_from", "!=", False), ("zip_to", "!=", False)]) | ||
) | ||
for carrier in carriers: | ||
carrier.write({"zip_from": carrier.zip_from, "zip_to": carrier.zip_to}) | ||
env.cr.execute("UPDATE delivery_carrier SET zip_from=NULL, zip_to=NULL") |
84 changes: 84 additions & 0 deletions
84
delivery_carrier_multi_zip/i18n/delivery_carrier_multi_zip.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * delivery_carrier_multi_zip | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__carrier_id | ||
msgid "Carrier" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__create_uid | ||
msgid "Created by" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__create_date | ||
msgid "Created on" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model,name:delivery_carrier_multi_zip.model_delivery_carrier_zip | ||
msgid "Delivery destination availability ZIP interval line" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__write_uid | ||
msgid "Last Updated by" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__write_date | ||
msgid "Last Updated on" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__name | ||
msgid "Name" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model,name:delivery_carrier_multi_zip.model_delivery_carrier | ||
msgid "Shipping Methods" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier__zip_ids | ||
msgid "ZIP codes" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__zip_from | ||
msgid "Zip From" | ||
msgstr "" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__zip_to | ||
msgid "Zip To" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * delivery_carrier_multi_zip | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2022-04-21 17:27+0000\n" | ||
"PO-Revision-Date: 2022-04-21 19:29+0200\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: es\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"X-Generator: Poedit 2.3\n" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__carrier_id | ||
msgid "Carrier" | ||
msgstr "Transportista" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__create_uid | ||
msgid "Created by" | ||
msgstr "Creado por" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__create_date | ||
msgid "Created on" | ||
msgstr "Creado el" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model,name:delivery_carrier_multi_zip.model_delivery_carrier_zip | ||
msgid "Delivery destination availability ZIP interval line" | ||
msgstr "Línea de intervalo de CP de disponibilidad de destino de transportista" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__display_name | ||
msgid "Display Name" | ||
msgstr "Nombre mostrado" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__id | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip____last_update | ||
msgid "Last Modified on" | ||
msgstr "Última modificación el" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__write_uid | ||
msgid "Last Updated by" | ||
msgstr "Última modificación por" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__write_date | ||
msgid "Last Updated on" | ||
msgstr "Última actualización el" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__name | ||
msgid "Name" | ||
msgstr "Nombre" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model,name:delivery_carrier_multi_zip.model_delivery_carrier | ||
msgid "Shipping Methods" | ||
msgstr "Métodos de envío" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier__zip_ids | ||
msgid "ZIP codes" | ||
msgstr "Códigos postales" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__zip_from | ||
msgid "Zip From" | ||
msgstr "Desde CP" | ||
|
||
#. module: delivery_carrier_multi_zip | ||
#: model:ir.model.fields,field_description:delivery_carrier_multi_zip.field_delivery_carrier_zip__zip_to | ||
msgid "Zip To" | ||
msgstr "Hasta CP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import delivery_carrier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2022 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class DeliveryCarrier(models.Model): | ||
_inherit = "delivery.carrier" | ||
|
||
zip_ids = fields.One2many( | ||
comodel_name="delivery.carrier.zip", | ||
inverse_name="carrier_id", | ||
string="ZIP codes", | ||
) | ||
|
||
@api.model | ||
def _convert_zip_to_intervals(self, vals): | ||
if self.env.context.get("bypass_multi_zip"): | ||
return | ||
if vals.get("zip_from") or vals.get("zip_to"): | ||
vals.setdefault("zip_ids", []) | ||
vals["zip_ids"].append( | ||
( | ||
0, | ||
0, | ||
{ | ||
"zip_from": vals.get("zip_from", "0") or "0", | ||
"zip_to": vals.get("zip_to", "z") or "z", | ||
}, | ||
) | ||
) | ||
vals.pop("zip_from", False) | ||
vals.pop("zip_to", False) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
"""Intercept creation for changing ZIP values to ZIP interval.""" | ||
for vals in vals_list: | ||
self._convert_zip_to_intervals(vals) | ||
return super().create(vals_list) | ||
|
||
def write(self, vals): | ||
"""Intercept write for changing ZIP values to ZIP interval.""" | ||
self._convert_zip_to_intervals(vals) | ||
return super().write(vals) | ||
|
||
def _match_address(self, partner): | ||
"""Match as well by zip intervals if they are present.""" | ||
res = super()._match_address(partner) # it has self.ensure_one() | ||
if res and self.zip_ids: | ||
partner_zip = partner.zip or "" | ||
res = bool( | ||
self.zip_ids.filtered( | ||
lambda r: r.zip_from <= partner_zip and r.zip_to >= partner_zip | ||
) | ||
) | ||
return res | ||
|
||
|
||
class DeliveryCarrierZip(models.Model): | ||
_name = "delivery.carrier.zip" | ||
_description = "Delivery destination availability ZIP interval line" | ||
|
||
carrier_id = fields.Many2one( | ||
comodel_name="delivery.carrier", ondelete="cascade", index=True | ||
) | ||
zip_from = fields.Char("Zip From", required=True) | ||
zip_to = fields.Char("Zip To", required=True) | ||
name = fields.Char(compute="_compute_name") | ||
|
||
@api.depends("zip_from", "zip_to") | ||
def _compute_name(self): | ||
for record in self: | ||
record.name = "%s - %s" % (record.zip_from, record.zip_to) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
To configure delivery methods with multiple ZIPs: | ||
|
||
#. Go to Inventory > Configuration > Delivery > Shipping Methods | ||
#. Create or edit an existing record. | ||
#. Introduce a line for each interval of zip codes. |
Oops, something went wrong.