class StockPickingTrackingLocationImportMapper(EasypostImportMapper): _model_name = 'easypost.shipment.tracking.location' direct = [ (eval_false('city'), 'city'), (eval_false('zip'), 'zip'), ] @mapping @only_create def odoo_id(self, record): rec = self.env['easypost.shipment.tracking.location'].search([ ('external_id', '=', record.id), ('backend_id', '=', self.backend_record.id), ]) if rec: return {'odoo_id': rec.odoo_id.id} @mapping @only_create def country_id(self, record): """ Load the country ID from the state code if it's not set. This is because the country code is not always included in `TrackingLocation` objects but the state is """ if record.country: country = self.env['res.country'].search([ ('code', '=', record.country), ]) return {'country_id': country.id} else: state = self.env['res.country.state'].search([ ('code', '=', record.state), ]) return {'country_id': state.country_id.id} @mapping @only_create def state_id(self, record): state = self.env['res.country.state'].search([ ('code', '=', record.state), ]) return {'state_id': state.id}
class StockPickingTrackingEventImportMapper(EasypostImportMapper): _model_name = 'easypost.stock.picking.tracking.event' direct = [ (eval_false('message'), 'message'), (eval_false('status'), 'state'), (eval_false('source'), 'source'), (eval_false('datetime'), 'date_created'), ] @mapping @only_create def group_id(self, record): """ `group_id` is not present in the event object and should be injected by the caller """ return {'group_id': record.group.id} @mapping @only_create def location_id(self, record): return {'location_id': record.location_id}
class StockPickingTrackingGroupImportMapper(EasypostImportMapper): _model_name = 'easypost.stock.picking.tracking.group' direct = [ (eval_false('tracking_code'), 'ref'), ] @mapping @only_create def picking_id(self, record): pickings = self.env['easypost.stock.picking'].search([ ('easypost_id', '=', record.shipment_id), ]) if pickings: return {'picking_id': pickings.odoo_id.id}