changeset eb40161f76d4 in modules/carrier_subdivision:default
details: 
https://hg.tryton.org/modules/carrier_subdivision?cmd=changeset&node=eb40161f76d4
description:
        Rename zip into postal code

        issue9853
        review340411002
diffstat:

 carrier.py                                         |  30 +++---
 doc/index.rst                                      |   6 +-
 sale.py                                            |   8 +-
 tests/scenario_carrier_subdivision_postal_code.rst |  97 ++++++++++++++++++++++
 tests/scenario_carrier_subdivision_zip.rst         |  97 ----------------------
 tests/test_carrier_subdivision.py                  |   2 +-
 view/carrier_selection_form.xml                    |   8 +-
 view/carrier_selection_list.xml                    |   4 +-
 8 files changed, 127 insertions(+), 125 deletions(-)

diffs (354 lines):

diff -r bffa51c396ec -r eb40161f76d4 carrier.py
--- a/carrier.py        Thu Jan 28 14:58:30 2021 +0100
+++ b/carrier.py        Wed Mar 31 23:59:33 2021 +0200
@@ -21,10 +21,11 @@
         depends=['from_country'],
         help="The subdivision the carrier collects from.\n"
         "Leave empty to allow collection from any subdivision.")
-    from_zip = fields.Char("From ZIP",
+    from_postal_code = fields.Char("From Postal Code",
         help=""
-        "The regular expression to match the zips the carrier collects from."
-        "\nLeave empty to allow collection from any ZIP.")
+        "The regular expression to match the postal codes "
+        "the carrier collects from.\n"
+        "Leave empty to allow collection from any postal code.")
     to_subdivision = fields.Many2One(
         'country.subdivision', "To Subdivision", ondelete='RESTRICT',
         domain=[
@@ -36,10 +37,11 @@
         depends=['to_country'],
         help="The subdivision the carrier delivers to.\n"
         "Leave empty to allow delivery to any subdivision.")
-    to_zip = fields.Char("To ZIP",
+    to_postal_code = fields.Char("To Postal Code",
         help=""
-        "The regular expression to match the zips the carrier collects to."
-        "\nLeave empty to allow collection to any ZIP.")
+        "The regular expression to match the postal codes "
+        "the carrier delivers to.\n"
+        "Leave empty to allow delivery to any postal code.")
 
     def match(self, pattern):
         pool = Pool()
@@ -60,11 +62,11 @@
                     and self.from_subdivision not in parents(
                         from_subdivision)):
                 return False
-        if 'from_zip' in pattern:
+        if 'from_postal_code' in pattern:
             pattern = pattern.copy()
-            from_zip = pattern.pop('from_zip') or ''
-            if (self.from_zip is not None
-                    and not re.match(self.from_zip, from_zip)):
+            from_postal_code = pattern.pop('from_postal_code') or ''
+            if (self.from_postal_code is not None
+                    and not re.match(self.from_postal_code, from_postal_code)):
                 return False
         if 'to_subdivision' in pattern:
             pattern = pattern.copy()
@@ -72,10 +74,10 @@
             if (self.to_subdivision is not None
                     and self.to_subdivision not in parents(to_subdivision)):
                 return False
-        if 'to_zip' in pattern:
+        if 'to_postal_code' in pattern:
             pattern = pattern.copy()
-            to_zip = pattern.pop('to_zip') or ''
-            if (self.to_zip is not None
-                    and not re.search(self.to_zip, to_zip)):
+            to_postal_code = pattern.pop('to_postal_code') or ''
+            if (self.to_postal_code is not None
+                    and not re.search(self.to_postal_code, to_postal_code)):
                 return False
         return super().match(pattern)
diff -r bffa51c396ec -r eb40161f76d4 doc/index.rst
--- a/doc/index.rst     Thu Jan 28 14:58:30 2021 +0100
+++ b/doc/index.rst     Wed Mar 31 23:59:33 2021 +0200
@@ -4,9 +4,9 @@
 This module extends the carrier selection pattern with:
 
 * The warehouse Subdivision
-* A regular expression to match against warehouse zip
+* A regular expression to match against warehouse postal code
 * The customer Subdivision
-* A regular expression to match against customer zip
+* A regular expression to match against customer postal code
 
 These can be used to restrict the usage of a carrier to a specific subdivision
-or a specific ZIP codes.
+or a specific postal code.
diff -r bffa51c396ec -r eb40161f76d4 sale.py
--- a/sale.py   Thu Jan 28 14:58:30 2021 +0100
+++ b/sale.py   Wed Mar 31 23:59:33 2021 +0200
@@ -19,13 +19,13 @@
             address = self.warehouse.address
             if address.subdivision:
                 pattern['from_subdivision'] = address.subdivision.id
-            if address.zip:
-                pattern['from_zip'] = address.zip
+            if address.postal_code:
+                pattern['from_postal_code'] = address.postal_code
         pattern['to_subdivision'] = None
         if self.shipment_address:
             address = self.shipment_address
             if address.subdivision:
                 pattern['to_subdivision'] = address.subdivision.id
-            if address.zip:
-                pattern['to_zip'] = address.zip
+            if address.postal_code:
+                pattern['to_postal_code'] = address.postal_code
         return pattern
diff -r bffa51c396ec -r eb40161f76d4 
tests/scenario_carrier_subdivision_postal_code.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_carrier_subdivision_postal_code.rst        Wed Mar 31 
23:59:33 2021 +0200
@@ -0,0 +1,97 @@
+========================================
+Carrier Subdivision Postal Code Scenario
+========================================
+
+Imports::
+
+    >>> from decimal import Decimal
+    >>> from proteus import Model
+    >>> from trytond.tests.tools import activate_modules
+    >>> from trytond.modules.company.tests.tools import (
+    ...     create_company, get_company)
+
+Activate modules::
+
+    >>> config = activate_modules(['carrier_subdivision', 
'sale_shipment_cost'])
+
+Create company::
+
+    >>> _ = create_company()
+    >>> company = get_company()
+
+Create customers::
+
+    >>> Party = Model.get('party.party')
+    >>> customer = Party(name='Customer')
+    >>> address, = customer.addresses
+    >>> address.postal_code = '08080'
+    >>> customer.save()
+    >>> other_customer = Party(name='Other Customer')
+    >>> address, = other_customer.addresses
+    >>> address.postal_code = '25175'
+    >>> other_customer.save()
+
+Create product::
+
+    >>> ProductUom = Model.get('product.uom')
+    >>> ProductTemplate = Model.get('product.template')
+    >>> unit, = ProductUom.find([('name', '=', 'Unit')])
+
+    >>> template = ProductTemplate()
+    >>> template.name = 'Product'
+    >>> template.default_uom = unit
+    >>> template.type = 'goods'
+    >>> template.salable = True
+    >>> template.list_price = Decimal('20')
+    >>> template.save()
+    >>> product, = template.products
+
+    >>> carrier_template = ProductTemplate()
+    >>> carrier_template.name = 'Carrier Product'
+    >>> carrier_template.default_uom = unit
+    >>> carrier_template.type = 'service'
+    >>> carrier_template.salable = True
+    >>> carrier_template.list_price = Decimal('3')
+    >>> carrier_template.save()
+    >>> carrier_product, = carrier_template.products
+
+Create carriers::
+
+    >>> Carrier = Model.get('carrier')
+    >>> carrier = Carrier()
+    >>> party = Party(name='Carrier')
+    >>> party.save()
+    >>> carrier.party = party
+    >>> carrier.carrier_product = carrier_product
+    >>> carrier.save()
+    >>> local_carrier = Carrier()
+    >>> party = Party(name='Local Carrier')
+    >>> party.save()
+    >>> local_carrier.party = party
+    >>> local_carrier.carrier_product = carrier_product
+    >>> local_carrier.save()
+
+Create postal code selection for each carrier::
+
+    >>> CarrierSelection = Model.get('carrier.selection')
+    >>> csc = CarrierSelection()
+    >>> csc.carrier = local_carrier
+    >>> csc.to_postal_code = '25'
+    >>> csc.sequence = 10
+    >>> csc.save()
+    >>> csc = CarrierSelection()
+    >>> csc.carrier = carrier
+    >>> csc.sequence = 20
+    >>> csc.save()
+
+Test right carrier is used on sale::
+
+    >>> Sale = Model.get('sale.sale')
+    >>> sale = Sale()
+    >>> sale.party = customer
+    >>> sale.carrier == carrier
+    True
+    >>> sale.carrier = None
+    >>> sale.party = other_customer
+    >>> sale.carrier == local_carrier
+    True
diff -r bffa51c396ec -r eb40161f76d4 tests/scenario_carrier_subdivision_zip.rst
--- a/tests/scenario_carrier_subdivision_zip.rst        Thu Jan 28 14:58:30 
2021 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-================================
-Carrier Subdivision ZIP Scenario
-================================
-
-Imports::
-
-    >>> from decimal import Decimal
-    >>> from proteus import Model
-    >>> from trytond.tests.tools import activate_modules
-    >>> from trytond.modules.company.tests.tools import (
-    ...     create_company, get_company)
-
-Activate modules::
-
-    >>> config = activate_modules(['carrier_subdivision', 
'sale_shipment_cost'])
-
-Create company::
-
-    >>> _ = create_company()
-    >>> company = get_company()
-
-Create customers::
-
-    >>> Party = Model.get('party.party')
-    >>> customer = Party(name='Customer')
-    >>> address, = customer.addresses
-    >>> address.zip = '08080'
-    >>> customer.save()
-    >>> other_customer = Party(name='Other Customer')
-    >>> address, = other_customer.addresses
-    >>> address.zip = '25175'
-    >>> other_customer.save()
-
-Create product::
-
-    >>> ProductUom = Model.get('product.uom')
-    >>> ProductTemplate = Model.get('product.template')
-    >>> unit, = ProductUom.find([('name', '=', 'Unit')])
-
-    >>> template = ProductTemplate()
-    >>> template.name = 'Product'
-    >>> template.default_uom = unit
-    >>> template.type = 'goods'
-    >>> template.salable = True
-    >>> template.list_price = Decimal('20')
-    >>> template.save()
-    >>> product, = template.products
-
-    >>> carrier_template = ProductTemplate()
-    >>> carrier_template.name = 'Carrier Product'
-    >>> carrier_template.default_uom = unit
-    >>> carrier_template.type = 'service'
-    >>> carrier_template.salable = True
-    >>> carrier_template.list_price = Decimal('3')
-    >>> carrier_template.save()
-    >>> carrier_product, = carrier_template.products
-
-Create carriers::
-
-    >>> Carrier = Model.get('carrier')
-    >>> carrier = Carrier()
-    >>> party = Party(name='Carrier')
-    >>> party.save()
-    >>> carrier.party = party
-    >>> carrier.carrier_product = carrier_product
-    >>> carrier.save()
-    >>> local_carrier = Carrier()
-    >>> party = Party(name='Local Carrier')
-    >>> party.save()
-    >>> local_carrier.party = party
-    >>> local_carrier.carrier_product = carrier_product
-    >>> local_carrier.save()
-
-Create zip selection for each carrier::
-
-    >>> CarrierSelection = Model.get('carrier.selection')
-    >>> csc = CarrierSelection()
-    >>> csc.carrier = local_carrier
-    >>> csc.to_zip = '25'
-    >>> csc.sequence = 10
-    >>> csc.save()
-    >>> csc = CarrierSelection()
-    >>> csc.carrier = carrier
-    >>> csc.sequence = 20
-    >>> csc.save()
-
-Test right carrier is used on sale::
-
-    >>> Sale = Model.get('sale.sale')
-    >>> sale = Sale()
-    >>> sale.party = customer
-    >>> sale.carrier == carrier
-    True
-    >>> sale.carrier = None
-    >>> sale.party = other_customer
-    >>> sale.carrier == local_carrier
-    True
diff -r bffa51c396ec -r eb40161f76d4 tests/test_carrier_subdivision.py
--- a/tests/test_carrier_subdivision.py Thu Jan 28 14:58:30 2021 +0100
+++ b/tests/test_carrier_subdivision.py Wed Mar 31 23:59:33 2021 +0200
@@ -25,7 +25,7 @@
             checker=doctest_checker,
             optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
     suite.addTests(doctest.DocFileSuite(
-            'scenario_carrier_subdivision_zip.rst',
+            'scenario_carrier_subdivision_postal_code.rst',
             tearDown=doctest_teardown, encoding='utf-8',
             checker=doctest_checker,
             optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
diff -r bffa51c396ec -r eb40161f76d4 view/carrier_selection_form.xml
--- a/view/carrier_selection_form.xml   Thu Jan 28 14:58:30 2021 +0100
+++ b/view/carrier_selection_form.xml   Wed Mar 31 23:59:33 2021 +0200
@@ -5,15 +5,15 @@
     <xpath expr="/form/field[@name='from_country']" position="after">
         <label name="from_subdivision"/>
         <field name="from_subdivision"/>
-        <label name="from_zip"/>
-        <field name="from_zip"/>
+        <label name="from_postal_code"/>
+        <field name="from_postal_code"/>
         <newline/>
     </xpath>
     <xpath expr="/form/field[@name='to_country']" position="after">
         <label name="to_subdivision"/>
         <field name="to_subdivision"/>
-        <label name="to_zip"/>
-        <field name="to_zip"/>
+        <label name="to_postal_code"/>
+        <field name="to_postal_code"/>
         <newline/>
     </xpath>
 </data>
diff -r bffa51c396ec -r eb40161f76d4 view/carrier_selection_list.xml
--- a/view/carrier_selection_list.xml   Thu Jan 28 14:58:30 2021 +0100
+++ b/view/carrier_selection_list.xml   Wed Mar 31 23:59:33 2021 +0200
@@ -4,10 +4,10 @@
 <data>
     <xpath expr="/tree/field[@name='from_country']" position="after">
         <field name="from_subdivision"/>
-        <field name="from_zip"/>
+        <field name="from_postal_code"/>
     </xpath>
     <xpath expr="/tree/field[@name='to_country']" position="after">
         <field name="to_subdivision"/>
-        <field name="to_zip"/>
+        <field name="to_postal_code"/>
     </xpath>
 </data>

Reply via email to