pickup: Fix datetime / timezone conversion
This commit is contained in:
parent
0a4df5f71a
commit
b52818b41a
|
@ -1,5 +1,6 @@
|
|||
from openerp import api, fields, models
|
||||
import logging
|
||||
import pytz
|
||||
from openerp.exceptions import Warning
|
||||
from shipcloud_delivery_carrier import build_sc_addr
|
||||
|
||||
|
@ -38,6 +39,12 @@ class SCPickup(models.Model):
|
|||
|
||||
@api.one
|
||||
def button_request(self):
|
||||
def field_to_datetime(self, dtfield):
|
||||
tz_name = self._context.get('tz') or self.env.user.tz
|
||||
tz = pytz.timezone(tz_name)
|
||||
dt = fields.Datetime.from_string(dtfield)
|
||||
return fields.Datetime.context_timestamp(self, dt)
|
||||
|
||||
# consistency check
|
||||
for p in self.pickings:
|
||||
if p.carrier_id.delivery_type != 'sc':
|
||||
|
@ -51,9 +58,9 @@ class SCPickup(models.Model):
|
|||
for p in self.pickings:
|
||||
sc_ship_ids.append({'id': p.sc_shipment_id})
|
||||
sc_addr = build_sc_addr(self.address)
|
||||
sc_earliest = fields.Datetime.from_string(self.earliest).astimezone().isoformat()
|
||||
sc_earliest = field_to_datetime(self, self.earliest).isoformat()
|
||||
sc_latest = field_to_datetime(self, self.latest).isoformat()
|
||||
_logger.info("earliest: %s -> %s" % (self.earliest, sc_earliest))
|
||||
sc_latest = fields.Datetime.from_string(self.latest).astimezone().isoformat()
|
||||
sc_pickup = shipcloud.gen_pickup(sc_addr, sc_earliest, sc_latest, sc_ship_ids, self.carrier)
|
||||
# actually use the SC API to request the pickup
|
||||
api = self._shipcloud_api()
|
||||
|
|
Loading…
Reference in New Issue