def update_suppliers(data_api_endpoint, data_api_token, updates_path, updated_by): client = DataAPIClient(data_api_endpoint, data_api_token) for update in load_updates(updates_path): print("Updating {}".format(update)) client.update_supplier(update.pop('id'), update, updated_by)
contact_update.update({ "address1": supplier_framework["declaration"]["registeredAddressBuilding"], "city": supplier_framework["declaration"]["registeredAddressTown"], "postcode": supplier_framework["declaration"]["registeredAddressPostcode"], }) elif (contact.get("address2") or "").strip(): # rescue any remaining data in address2 contact_update["address1"] = u", ".join((contact["address1"].strip(), contact["address2"].strip())) # we're going to deprecate this field contact_update["address2"] = "" logger.info("supplier_update = %s", pformat(supplier_update)) if not dry_run: try: client.update_supplier(supplier["id"], supplier_update, user=user) except HTTPError as hte: if 'duplicate key value violates unique constraint "ix_suppliers_duns_number"' in hte.message: logger.info("DUNS clash {} for supplier {}".format(supplier_update['dunsNumber'], supplier['id'])) supplier_update.pop('dunsNumber', None) logger.info("revised supplier_update = %s", pformat(supplier_update)) client.update_supplier(supplier["id"], supplier_update, user=user) else: logger.info("HTTP ERROR UPDATING SUPPLIER {}".format(supplier['id'])) logger.info("contact_update = %s", pformat(contact_update)) if not dry_run: client.update_contact_information( supplier["id"], contact["id"], contact_update,