Added method get_carriers_from_zip to Carrier model

This commit is contained in:
jmartin 2015-02-23 16:30:42 +01:00
parent 9d14e138c5
commit a29d955689
1 changed files with 10 additions and 1 deletions

View File

@ -2,7 +2,7 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
__metaclass__ = PoolMeta
__all__ = ['CarrierZip', 'Carrier']
@ -40,3 +40,12 @@ class CarrierZip(ModelSQL, ModelView):
class Carrier:
__name__ = 'carrier'
zips = fields.One2Many('carrier.zip', 'carrier', 'Carrier Zips')
@staticmethod
def get_carriers_from_zip(zip_code):
CarrierZip = Pool().get('carrier.zip')
carrier_zips = CarrierZip.search([
('start_zip', '<=', zip_code),
('end_zip', '>=', zip_code),
])
return [c.carrier for c in carrier_zips]