Rename zip into postal code (issue9853)
This commit is contained in:
parent
8cfb34293a
commit
619b8e9f2b
39
carrier.py
39
carrier.py
|
@ -5,20 +5,18 @@ from trytond.model import fields
|
|||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import If, Bool, Eval
|
||||
|
||||
__all__ = ['CarrierSelection']
|
||||
|
||||
|
||||
class CarrierSelection(metaclass=PoolMeta):
|
||||
__name__ = 'carrier.selection'
|
||||
|
||||
start_zip = fields.Many2One('country.zip', 'Start Zip',
|
||||
domain=[
|
||||
start_postal_code = fields.Many2One('country.postal_code',
|
||||
'Start Postal Code', domain=[
|
||||
If(Bool(Eval('to_country')),
|
||||
('country', '=', Eval('to_country')),
|
||||
(),
|
||||
)],
|
||||
depends=['to_country'])
|
||||
end_zip = fields.Many2One('country.zip', 'End Zip',
|
||||
end_postal_code = fields.Many2One('country.postal_code', 'End Postal Code',
|
||||
domain=[
|
||||
If(Bool(Eval('to_country')),
|
||||
('country', '=', Eval('to_country')),
|
||||
|
@ -26,22 +24,31 @@ class CarrierSelection(metaclass=PoolMeta):
|
|||
)],
|
||||
depends=['to_country'])
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module):
|
||||
# Migration from 5.8: rename zip to postal_code
|
||||
table_h = cls.__table_handler__(module)
|
||||
table_h.column_rename('start_zip', 'start_postal_code')
|
||||
table_h.column_rename('end_zip', 'end_postal_code')
|
||||
super().__register__(module)
|
||||
|
||||
def match(self, pattern):
|
||||
if 'shipment_zip' in pattern:
|
||||
if 'shipment_postal_code' in pattern:
|
||||
pattern = pattern.copy()
|
||||
shipment_zip = pattern.pop('shipment_zip')
|
||||
if (self.start_zip or self.end_zip) and shipment_zip:
|
||||
start_zip, end_zip = None, None
|
||||
shipment_postal_code = pattern.pop('shipment_postal_code')
|
||||
if ((self.start_postal_code or self.end_postal_code)
|
||||
and shipment_postal_code):
|
||||
start_postal_code, end_postal_code = None, None
|
||||
try:
|
||||
zip = int(shipment_zip)
|
||||
if self.start_zip:
|
||||
start_zip = int(self.start_zip.zip)
|
||||
if self.end_zip:
|
||||
end_zip = int(self.end_zip.zip)
|
||||
postal_code = int(shipment_postal_code)
|
||||
if self.start_postal_code:
|
||||
start_postal_code = int(self.start_postal_code.postal_code)
|
||||
if self.end_postal_code:
|
||||
end_postal_code = int(self.end_postal_code.postal_code)
|
||||
except ValueError:
|
||||
pass
|
||||
if start_zip and zip < start_zip:
|
||||
if start_postal_code and postal_code < start_postal_code:
|
||||
return False
|
||||
if end_zip and zip > end_zip:
|
||||
if end_postal_code and postal_code > end_postal_code:
|
||||
return False
|
||||
return super(CarrierSelection, self).match(pattern)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Carrier Zip Module
|
||||
##################
|
||||
|
||||
The carrier zip module add domain carriers with zip address. This module work
|
||||
with Spain zips because use numeric codes.
|
||||
The carrier zip module add domain carriers with postal code address. This
|
||||
module work with Spain postal codes because use numeric codes.
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier.selection,end_zip:"
|
||||
msgid "End Zip"
|
||||
msgctxt "field:carrier.selection,end_postal_code:"
|
||||
msgid "End Postal Code"
|
||||
msgstr "Codi postal final"
|
||||
|
||||
msgctxt "field:carrier.selection,start_zip:"
|
||||
msgid "Start Zip"
|
||||
msgctxt "field:carrier.selection,start_postal_code:"
|
||||
msgid "Start Postal Code"
|
||||
msgstr "Codi postal inici"
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:carrier.selection,end_zip:"
|
||||
msgid "End Zip"
|
||||
msgctxt "field:carrier.selection,end_postal_code:"
|
||||
msgid "End Postal Code"
|
||||
msgstr "Código postal final"
|
||||
|
||||
msgctxt "field:carrier.selection,start_zip:"
|
||||
msgid "Start Zip"
|
||||
msgctxt "field:carrier.selection,start_postal_code:"
|
||||
msgid "Start Postal Code"
|
||||
msgstr "Código postal inicio"
|
||||
|
|
8
sale.py
8
sale.py
|
@ -4,8 +4,6 @@
|
|||
from trytond.pool import PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Sale']
|
||||
|
||||
|
||||
class Sale(metaclass=PoolMeta):
|
||||
__name__ = 'sale.sale'
|
||||
|
@ -13,14 +11,14 @@ class Sale(metaclass=PoolMeta):
|
|||
def _get_carrier_selection_pattern(self):
|
||||
pattern = super(Sale, self)._get_carrier_selection_pattern()
|
||||
if self.shipment_address:
|
||||
pattern['shipment_zip'] = self.shipment_address.zip
|
||||
pattern['shipment_postal_code'] = self.shipment_address.postal_code
|
||||
return pattern
|
||||
|
||||
def _get_carrier_context(self):
|
||||
context = super(Sale, self)._get_carrier_context()
|
||||
if self.carrier and self.carrier.carrier_cost_method == 'grid':
|
||||
context['shipment_zip'] = (self.shipment_address
|
||||
and self.shipment_address.zip or None)
|
||||
context['shipment_postal_code'] = (self.shipment_address
|
||||
and self.shipment_address.postal_code or None)
|
||||
return context
|
||||
|
||||
def create_shipment(self, shipment_type):
|
||||
|
|
|
@ -39,26 +39,27 @@ Create chart of accounts::
|
|||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create some zip codes::
|
||||
Create some postal codes::
|
||||
|
||||
>>> Country = Model.get('country.country')
|
||||
>>> Zip = Model.get('country.zip')
|
||||
>>> PostalCode = Model.get('country.postal_code')
|
||||
>>> country = Country(name='Country')
|
||||
>>> country.save()
|
||||
>>> Zip.save([Zip(country=country, zip=str(i)) for i in range(10)])
|
||||
>>> PostalCode.save([PostalCode(country=country, postal_code=str(i))
|
||||
... for i in range(10)])
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> address, = customer.addresses
|
||||
>>> zip, = Zip.find([('zip', '=', '2')])
|
||||
>>> address.zip = zip.zip
|
||||
>>> postal_code, = PostalCode.find([('postal_code', '=', '2')])
|
||||
>>> address.postal_code = postal_code.postal_code
|
||||
>>> customer.save()
|
||||
>>> other_customer = Party(name='Other Customer')
|
||||
>>> address, = other_customer.addresses
|
||||
>>> zip, = Zip.find([('zip', '=', '7')])
|
||||
>>> address.zip = zip.zip
|
||||
>>> postal_code, = PostalCode.find([('postal_code', '=', '7')])
|
||||
>>> address.postal_code = postal_code.postal_code
|
||||
>>> other_customer.save()
|
||||
|
||||
Create product::
|
||||
|
@ -98,12 +99,12 @@ Create carrier::
|
|||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.save()
|
||||
|
||||
Create a selection for zips from 1 to 5::
|
||||
Create a selection for postal_code from 1 to 5::
|
||||
|
||||
>>> CarrierSelection = Model.get('carrier.selection')
|
||||
>>> csc = CarrierSelection(carrier=carrier)
|
||||
>>> csc.start_zip, = Zip.find([('zip', '=', '1')])
|
||||
>>> csc.end_zip, = Zip.find([('zip', '=', '5')])
|
||||
>>> csc.start_postal_code, = PostalCode.find([('postal_code', '=', '1')])
|
||||
>>> csc.end_postal_code, = PostalCode.find([('postal_code', '=', '5')])
|
||||
>>> csc.save()
|
||||
|
||||
The carrier is selected for customer::
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of the carrier_zip module for Tryton.
|
||||
<!-- This file is part of the carrier_postal_code module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='to_country']" position="after">
|
||||
<label name="start_zip"/>
|
||||
<field name="start_zip"/>
|
||||
<label name="end_zip"/>
|
||||
<field name="end_zip"/>
|
||||
<label name="start_postal_code"/>
|
||||
<field name="start_postal_code"/>
|
||||
<label name="end_postal_code"/>
|
||||
<field name="end_postal_code"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of the carrier_zip module for Tryton.
|
||||
<!-- This file is part of the carrier_postal_code module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='to_country']" position="after">
|
||||
<field name="start_zip"/>
|
||||
<field name="end_zip"/>
|
||||
<field name="start_postal_code"/>
|
||||
<field name="end_postal_code"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue