def import_contact(obj_xml, context): contact = objectify.fromstring(obj_xml) # Note: There is a 'first_last_name' field, but it's not documented, so # better ignore it obj_id = "%s:%s" % (context.id_prefix, contact.id) name = unicode(contact.first_name) + ' ' + unicode(contact.last_name) db_contact, _ = dbutils.update_or_create(Contact, external_id=obj_id, name=name) if hasattr(contact, 'job_title'): db_contact.function = unicode(contact.job_title) if hasattr(contact, 'contact_items'): import_contact_items(db_contact, contact.contact_items) db_contact.save() if hasattr(contact, 'firm_id'): organisation = ClientOrganisation.objects.get( company__external_id="%s:%s" % (context.id_prefix, contact.firm_id), name=DEFAULT_CLIENT_ORGANIZATION_NAME) Client.objects.get_or_create(contact=db_contact, organisation=organisation)
def import_contact(obj_xml, context): contact = objectify.fromstring(obj_xml) # Note: There is a 'first_last_name' field, but it's not documented, so # better ignore it obj_id = "%s:%s" % (context.id_prefix, contact.id) name = unicode(contact.first_name) + ' ' + unicode(contact.last_name) db_contact, _ = dbutils.update_or_create(Contact, external_id=obj_id, name=name) if hasattr(contact, 'job_title'): db_contact.function = unicode(contact.job_title) if hasattr(contact, 'contact_items'): import_contact_items(db_contact, contact.contact_items) db_contact.save() if hasattr(contact, 'firm_id'): organisation = ClientOrganisation.objects.get(company__external_id="%s:%s" % (context.id_prefix, contact.firm_id), name=DEFAULT_CLIENT_ORGANIZATION_NAME) Client.objects.get_or_create(contact=db_contact, organisation=organisation)
def import_proposal_sheet(obj_xml, context): sheet = objectify.fromstring(obj_xml) obj_id = "%s:%s" % (context.id_prefix, sheet.id) if sheet.sheet_type != 'proposal': logger.warning('Skipping proposal sheet %d: sheet_type is %s', obj_id, sheet.sheet_type) return state = STATE_FOR_PROGRESS_ID[sheet.progress_id] if state != 'WON': logger.warning('Skipping proposal sheet %s: not won', obj_id) return firm_id = sheet.firm_id if hasattr(sheet, 'firm_id') else 0 contact_id = sheet.contact_id if hasattr(sheet, 'contact_id') else 0 if firm_id == 0 and contact_id == 0: raise IncwoImportError('Invalid proposal sheet {}: neither firm_id nor contact_id are set'.format(obj_id)) name = unicode(sheet.title).strip() if contact_id > 0: # Find client from contact, use the default organisation client = Client.objects.get(contact__external_id="%s:%s" % (context.id_prefix, sheet.contact_id), organisation__name=DEFAULT_CLIENT_ORGANIZATION_NAME) else: # Find client from company, use the default organisation and the # default, contact-less, client client = Client.objects.get(organisation__company__external_id="%s:%s" % (context.id_prefix, sheet.firm_id), organisation__name=DEFAULT_CLIENT_ORGANIZATION_NAME, contact=None) lead, _ = dbutils.update_or_create(Lead, external_id=obj_id, name=name, client=client, subsidiary=context.subsidiary, state=state, creation_date=_parse_incwo_date(unicode(sheet.billing_date)), description=unicode(sheet.subtitle).strip(), deal_id=unicode(sheet.reference).strip()) if hasattr(sheet, 'proposal_lines') and context.import_missions: lst = list(sheet.proposal_lines.iterchildren()) proposal_line_context = ProposalLineContext() lines = [] if lead.description: lines.append(lead.description) for pos, proposal_line in enumerate(lst): logger.info('- Proposal line %d/%d', pos + 1, len(lst)) lines.append(import_proposal_line(proposal_line, proposal_line_context)) lead.description = '\n'.join(lines) lead.sales = proposal_line_context.grand_total() / 1000 # grand_total is in €, but lead.sales is in k€ lead.save() mission_lst = Mission.objects.filter(lead=lead) if len(mission_lst) == 0: mission = create_default_mission(lead) mission.billing_mode = 'FIXED_PRICE' mission.save() elif len(mission_lst) == 1: # Only one mission, assume it's the default mission and update it # based on the lead mission = mission_lst[0] mission.price = lead.sales
def import_proposal_sheet(obj_xml, context): sheet = objectify.fromstring(obj_xml) obj_id = "%s:%s" % (context.id_prefix, sheet.id) if sheet.sheet_type != 'proposal': logger.warning('Skipping proposal sheet %d: sheet_type is %s', obj_id, sheet.sheet_type) return state = STATE_FOR_PROGRESS_ID[sheet.progress_id] if state != 'WON': logger.warning('Skipping proposal sheet %s: not won', obj_id) return firm_id = sheet.firm_id if hasattr(sheet, 'firm_id') else 0 contact_id = sheet.contact_id if hasattr(sheet, 'contact_id') else 0 if firm_id == 0 and contact_id == 0: raise IncwoImportError( 'Invalid proposal sheet {}: neither firm_id nor contact_id are set' .format(obj_id)) name = unicode(sheet.title).strip() if contact_id > 0: # Find client from contact, use the default organisation client = Client.objects.get( contact__external_id="%s:%s" % (context.id_prefix, sheet.contact_id), organisation__name=DEFAULT_CLIENT_ORGANIZATION_NAME) else: # Find client from company, use the default organisation and the # default, contact-less, client client = Client.objects.get( organisation__company__external_id="%s:%s" % (context.id_prefix, sheet.firm_id), organisation__name=DEFAULT_CLIENT_ORGANIZATION_NAME, contact=None) lead, _ = dbutils.update_or_create( Lead, external_id=obj_id, name=name, client=client, subsidiary=context.subsidiary, state=state, creation_date=_parse_incwo_date(unicode(sheet.billing_date)), description=unicode(sheet.subtitle).strip(), deal_id=unicode(sheet.reference).strip()) if hasattr(sheet, 'proposal_lines') and context.import_missions: lst = list(sheet.proposal_lines.iterchildren()) proposal_line_context = ProposalLineContext() lines = [] if lead.description: lines.append(lead.description) for pos, proposal_line in enumerate(lst): logger.info('- Proposal line %d/%d', pos + 1, len(lst)) lines.append( import_proposal_line(proposal_line, proposal_line_context)) lead.description = '\n'.join(lines) lead.sales = proposal_line_context.grand_total( ) / 1000 # grand_total is in €, but lead.sales is in k€ lead.save() mission_lst = Mission.objects.filter(lead=lead) if len(mission_lst) == 0: mission = create_default_mission(lead) mission.billing_mode = 'FIXED_PRICE' mission.save() elif len(mission_lst) == 1: # Only one mission, assume it's the default mission and update it # based on the lead mission = mission_lst[0] mission.price = lead.sales