class MyMapper(Component): _name = "my.mapper" _inherit = "base.import.mapper" direct = [ (none(convert("in_f", bool)), "out_f"), (none(convert("in_t", bool)), "out_t"), ]
class HelpScoutWebHookExportMapper(Component): _name = 'helpscout.export.mapper.web.hook' _inherit = 'helpscout.export.mapper' _apply_on = 'helpscout.web.hook' direct = [(none('uri_json'), 'url'), (none('token_secret'), 'secret_key'), ] @mapping def events(self, _): """Subscribe to all events.""" return {'events': EVENT_CHOICES.keys()}
class EasypostShipmentImportMapper(Component): _name = 'easypost.import.mapper.shipment' _inherit = 'easypost.import.mapper' _apply_on = 'easypost.shipment' direct = [ (none('refund_status'), 'refund_status'), ]
class MyMapper(Component): _name = 'my.mapper' _inherit = 'base.export.mapper' direct = [('street', 'out_street'), (none('in_t'), 'out_t'), (none(convert('in_f', bool)), 'out_f')] @changed_by('name', 'city') @mapping def name(self): pass @changed_by('email') @mapping def email(self): pass def no_decorator(self): pass
class HelpScoutUserImportMapper(Component): _name = 'helpscout.import.mapper.user' _inherit = 'helpscout.import.mapper' _apply_on = 'helpscout.user' direct = [ (none('first_name'), 'firstname'), (none('last_name'), 'lastname'), ('email', 'login'), ('email', 'email'), (none('timezone'), 'tz'), (none('type'), 'helpscout_type'), ] @mapping @only_create def odoo_id(self, record): # Searches res.users records for matching email address, # excluding non-internal-users (e.g. customer users) user = self.env['res.users'].search([ (self.backend_record.user_match_field, '=', record.email), ('share', '=', False), ]) if user: return {'odoo_id': user.id} @mapping def photo_url(self, record): try: image = urllib2.urlopen(record.photo_url).read().encode('base64') return {'image': image} except Exception: _logger.debug('HelpScout photo not imported') return @mapping def role(self, record): group_xml_id = "connector_helpscout.group_helpscout_%s" % record.role helpscout_group = self.env.ref(group_xml_id) return {'groups_id': [(6, 0, [helpscout_group.id])]}
class MyMapper(Component): _name = "my.mapper" _inherit = "base.export.mapper" direct = [ ("street", "out_street"), (none("in_t"), "out_t"), (none(convert("in_f", bool)), "out_f"), ] @changed_by("name", "city") @mapping def name(self): pass @changed_by("email") @mapping def email(self): pass def no_decorator(self): pass
class HelpScoutCustomerExportMapper(Component): _name = 'helpscout.export.mapper.customer' _inherit = 'helpscout.export.mapper' _apply_on = 'helpscout.customer' direct = [ (none('firstname'), 'first_name'), (none('lastname'), 'last_name'), (none('comment'), 'background'), (none('function'), 'job_title'), ] @mapping def emails(self, record): if record.email: return {'emails': [{'value': record.email}]} @mapping def phones(self, record): phone_map = { 'phone': 'home', 'mobile': 'mobile', 'fax': 'fax', } phones = [] for odoo_type, helpscout_type in phone_map.items(): if record[odoo_type]: phones.append({ 'value': record[odoo_type], 'location': helpscout_type, }) if phones: return {'phones': phones} @mapping def websites(self, record): if record.website: return {'websites': [{'value': record.website}]}
class HelpScoutMailboxImportMapper(Component): _name = 'helpscout.import.mapper.mailbox' _inherit = 'helpscout.import.mapper' _apply_on = 'helpscout.mailbox' direct = [ ('name', 'name'), (none('email'), 'helpscout_email'), ] @mapping @only_create def odoo_id(self, record): # Searches project.project records for matching name project = self.env['project.project'].search([ ('name', '=', record.name), ]) if project: return {'odoo_id': project.id}
class HelpScoutConversationImportMapper(Component): _name = 'helpscout.import.mapper.conversation' _inherit = 'helpscout.import.mapper' _apply_on = 'helpscout.conversation' direct = [ (none('type'), 'helpscout_type'), (convert('number', str), 'code'), (none('subject'), 'name'), ] @mapping @only_create def odoo_id(self, record): conversation = self.env['project.task'].search([ ('code', '=', str(record.number)), ]) if conversation: return {'odoo_id': conversation.id} @mapping def helpscout_folder_id(self, record): folder = self.env['helpscout.helpscout.folder'].search([ ('external_id', '=', record.folder_id), ]) if folder: return {'helpscout_folder_id': folder.id} @mapping def partner_id(self, record): customer = self.env['helpscout.customer'].search([ ('external_id', '=', record.customer.id), ]) partner = customer.odoo_id return {'partner_id': partner.id} @mapping def project_id(self, record): mailbox = self.env['helpscout.mailbox'].search([ ('external_id', '=', record.mailbox.id), ]) project = mailbox.odoo_id if project: return {'project_id': project.id} @mapping def stage_id(self, record): stage = self.env.ref('connector_helpscout.status_%s' % record.status) if stage: return {'stage_id': stage.id} @mapping def tag_ids(self, record): tag_bindings = self.env['helpscout.tag'].search([ ('name', 'in', record.tags), ('backend_id', '=', self.backend_record.id), ]) if len(tag_bindings) != len(record.tags): self.env['helpscout.tag'].import_batch(self.backend_record) return self.tag_ids(record) tags = tag_bindings.mapped('odoo_id') if tags: return {'tag_ids': [(6, 0, tags.ids)]} @mapping def user_id(self, record): try: owner = self.env['helpscout.user'].search([ ('external_id', '=', record.owner.id), ]) except AttributeError: # in case a user/owner has not been assigned to the ticket return {'user_id': False} user = owner.odoo_id return {'user_id': user.id}
class MyMapper(Component): _name = 'my.mapper' _inherit = 'base.import.mapper' direct = [(none(convert('in_f', bool)), 'out_f'), (none(convert('in_t', bool)), 'out_t')]
class HelpScoutCustomerImportMapper(Component): _name = 'helpscout.import.mapper.customer' _inherit = 'helpscout.import.mapper' _apply_on = 'helpscout.customer' direct = [ (none('first_name'), 'firstname'), (none('last_name'), 'lastname'), (none('background'), 'comment'), (none('job_title'), 'function'), ] @mapping def email(self, record): try: return {'email': record.emails[0].value} except IndexError: return @mapping def full_name(self, record): """Ensure at least one name is provided""" if record.first_name or record.last_name: return if not record.full_name: return {'firstname': 'Unknown HelpScout Customer'} return {'firstname': record.full_name} @mapping @only_create def odoo_id(self, record): # Searches res.partner records for matching email address, # excluding internal users try: customer = self.env['res.partner'].search([ ('email', '=', self.email(record)['email']), ('user_id', '=', False), ]) except TypeError: # In case no email is found return if customer: return {'odoo_id': customer.id} @mapping def phones(self, record): phones = {} for phone in record.phones: if phone.location in ['fax', 'mobile']: phones[phone.location] = phone.value else: phones['phone'] = phone.value return phones @mapping def website(self, record): try: return {'website': record.websites[0].value} except IndexError: return